Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

C++ STL static library / string instantiation issue

807575May 21 2002 — edited Jun 7 2002
Summary:
Building a static library which uses vectors and strings from the STL appears to cause problems with string allocator in executable which links the static library.

Environment:
Forte 6 Update 2 C++ on SunOS 5.7

Details:
I am building a static library which uses <vector> and <string> in the standard template library (with default settings for all template-related options.) I am linking this library with another program which uses strings from the STL. When I run my program, string initialization doesn't appear to work. If I do this:

string r;
r = "text";
cout << r << endl;
string s;
cout << s << endl;

I get the following output:

text
text

No cache directory is created in the executable's build directory.

Alternately, if I do not define string r before defining string s, I get garbage data.

If I remove the static library from the Makefile in my test program, it behaves as expected...I get a blank string for s. Also, if I build with all the object files in the static library rather than linking the library, it runs as expected. I am therefore convinced that this is a template instantiation issue.

What could possibly be causing this problem and how could I fix it? I've been breaking my back over this for a week now.

I've attached the output from the build of the static library with verbose template information. Any

Build Output (abridged):
.
.
.
/opt/forte6/SUNWspro/WS6U2/bin/CC -I../tcprinting -I../tcqmanager -I../tcproperties/tcdmproperty -I../tcproperties/tcftpproperty -I../tcproperties/tcproperty -I../tcproperties/tcpropertymgr -I../tcserver -I../tcsocket -I../tcthread -I../tcutils -g -mt -D_PTHREAD -I/opt/forte6/SUNWspro/WS6U2/include/CC -verbose=template -o stringtokenizer.o -c stringtokenizer.cpp -o stringtokenizer.o
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 467: Information: Instantiating std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char>>>>::__insert_aux(std::basic_string<char, std::char_traits<char>, std::allocator<char>>*, const std::basic_string<char, std::char_traits<char>, std::allocator<char>>&).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector.cc", line 114: Information: Instantiating std::copy_backward<std::basic_string<char, std::char_traits<char>, std::allocator<char>>*, std::basic_string<char, std::char_traits<char>, std::allocator<char>>*>(std::basic_string<char, std::char_traits<char>, std::allocator<char>>*, std::basic_string<char, std::char_traits<char>, std::allocator<char>>*, std::basic_string<char, std::char_traits<char>, std::allocator<char>>*).
.
.
.
/opt/forte6/SUNWspro/WS6U2/bin/CC -I../tcprinting -I../tcqmanager -I../tcproperties/tcdmproperty -I../tcproperties/tcftpproperty -I../tcproperties/tcproperty -I../tcproperties/tcpropertymgr -I../tcserver -I../tcsocket -I../tcthread -I../tcutils -g -mt -D_PTHREAD -I/opt/forte6/SUNWspro/WS6U2/include/CC -verbose=template -o tclog.o -c tclog.cpp -o tclog.o
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 511: Information: Instantiating std::copy<tcResult*, tcResult*>(tcResult*, tcResult*, tcResult*).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 511: Information: Instantiating std::copy<unsigned*, unsigned*>(unsigned*, unsigned*, unsigned*).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 467: Information: Instantiating std::vector<long, std::allocator<long>>::__insert_aux(long*, const long&).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 467: Information: Instantiating std::vector<tcResult, std::allocator<tcResult>>::__insert_aux(tcResult*, const tcResult&).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector", line 467: Information: Instantiating std::vector<unsigned, std::allocator<unsigned>>::__insert_aux(unsigned*, const unsigned&).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector.cc", line 114: Information: Instantiating std::copy_backward<long*, long*>(long*, long*, long*).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector.cc", line 114: Information: Instantiating std::copy_backward<tcResult*, tcResult*>(tcResult*, tcResult*, tcResult*).
"/opt/forte6/SUNWspro/WS6U2/include/CC/Cstd/./vector.cc", line 114: Information: Instantiating std::copy_backward<unsigned*, unsigned*>(unsigned*, unsigned*, unsigned*).
/opt/forte6/SUNWspro/WS6U2/bin/CC -I../tcprinting -I../tcqmanager -I../tcproperties/tcdmproperty -I../tcproperties/tcftpproperty -I../tcproperties/tcproperty -I../tcproperties/tcpropertymgr -I../tcserver -I../tcsocket -I../tcthread -I../tcutils -g -mt -D_PTHREAD -I/opt/forte6/SUNWspro/WS6U2/include/CC -verbose=template -o tcmutex.o -c tcmutex.cpp -o tcmutex.o
.
.
.
/opt/forte6/SUNWspro/WS6U2/bin/CC -xar -o libtcutil.a binstream.o stringtokenizer.o tcconfigfile.o tcerror.o CmdLineParser.o tclog.o tcmutex.o tcseqno.o tcutils.o
cp libtcutil.a ../lib/libtcutil.a
Completed in Debug Mode

Tim Crist
tim.crist@usa.xerox.com

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2002
Added on May 21 2002
2 comments
269 views