Help linking debug version ( g++ )


Howdy all,

I am having a strange problem where my program compiles and links just fine with the -O2 flag set, but it only COMPILES with the -O0 -g flags set (i.e. debug version). It will not link and fails with the following:

/usr/local/lib/libQCUtilities_debug.so: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
/usr/local/lib/libQCUtilities_debug.so: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
/usr/local/lib/libQCUtilities_debug.so: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'

My g++ commandline is:

g++44 -o LogRelay_debug -W1,--verbose -v -Wall -pthread -std=c++0x -D_LINUX -DBOOST_SYSTEM_NO_DEPRECATED -O0 -g -I. -I/usr/local/include -I/usr/include -I. -I../QCLogServer LogRelayMain.debug.o -L/usr/local/lib -L/usr/lib64 -lstdc++ -lrt -lzmq -lboost_system -lboost_thread -lboost_date_time -lboost_filesystem -lboost_program_options -lboost_regex -lQCLog_debug -lQCUtilities_debug -lQCMessage_debug

readelf suggests that these symbols are in the library (which makes sense since the release version compiles):

[xxx@lx1 yyy]# readelf -a /usr/lib64/libstdc++.so | grep basic_ifstream
003a202e7150 00ae00000001 R_X86_64_64 0000003a202e7740 _ZTISt14basic_ifstream + 0
003a202e7178 00ae00000001 R_X86_64_64 0000003a202e7740 _ZTISt14basic_ifstream + 0
003a202e7158 0a4b00000001 R_X86_64_64 0000003a2006bb10 _ZNSt14basic_ifstreamI + 0
003a202e7160 097300000001 R_X86_64_64 0000003a2006bc60 _ZNSt14basic_ifstreamI + 0
003a202e71a0 082500000001 R_X86_64_64 0000003a202e7140 _ZTVSt14basic_ifstream + 18
003a202e71b8 082500000001 R_X86_64_64 0000003a202e7140 _ZTVSt14basic_ifstream + 40
003a202ebd08 082500000006 R_X86_64_GLOB_DAT 0000003a202e7140 _ZTVSt14basic_ifstream + 0
003a202e75b0 08a700000001 R_X86_64_64 0000003a202e77c0 _ZTISt14basic_ifstream + 0
003a202e75d8 08a700000001 R_X86_64_64 0000003a202e77c0 _ZTISt14basic_ifstream + 0
003a202e75b8 06c300000001 R_X86_64_64 0000003a2006bf50 _ZNSt14basic_ifstreamI + 0
003a202e75c0 05da00000001 R_X86_64_64 0000003a2006c020 _ZNSt14basic_ifstreamI + 0
003a202e7600 03ef00000001 R_X86_64_64 0000003a202e75a0 _ZTVSt14basic_ifstream + 18
003a202e7618 03ef00000001 R_X86_64_64 0000003a202e75a0 _ZTVSt14basic_ifstream + 40
003a202ebcf8 03ef00000006 R_X86_64_GLOB_DAT 0000003a202e75a0 _ZTVSt14basic_ifstream + 0
003a202e7748 0c4d00000001 R_X86_64_64 0000003a200c4bc0 _ZTSSt14basic_ifstream + 0
003a202e77c8 07d300000001 R_X86_64_64 0000003a200c4cc0 _ZTSSt14basic_ifstream + 0
003a202eb630 0af900000006 R_X86_64_GLOB_DAT 0000003a202e71a0 _ZTTSt14basic_ifstream + 0
003a202eb918 069800000006 R_X86_64_GLOB_DAT 0000003a202e7600 _ZTTSt14basic_ifstream + 0
174: 0000003a202e7740 24 OBJECT WEAK DEFAULT 21 _ZTISt14basic_ifstreamIwS@@GLIBCXX_3.4
182: 0000003a2006b820 267 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
187: 0000003a2006a6d0 61 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
1007: 0000003a202e75a0 80 OBJECT WEAK DEFAULT 21 _ZTVSt14basic_ifstreamIcS@@GLIBCXX_3.4
1176: 0000003a2006b6e0 313 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
1264: 0000003a20055410 40 FUNC GLOBAL DEFAULT 11 _ZNKSt14basic_ifstreamIwS@@GLIBCXX_3.4.5
1267: 0000003a20055410 40 FUNC GLOBAL DEFAULT 11 _ZNKSt14basic_ifstreamIwS@GLIBCXX_3.4
1389: 0000003a2006ba40 192 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
1498: 0000003a2006c020 200 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
1615: 0000003a200661f0 5 FUNC WEAK DEFAULT 11 _ZNKSt14basic_ifstreamIwS@@GLIBCXX_3.4
1688: 0000003a202e7600 32 OBJECT WEAK DEFAULT 21 _ZTTSt14basic_ifstreamIcS@@GLIBCXX_3.4
1694: 0000003a20055380 40 FUNC GLOBAL DEFAULT 11 _ZNKSt14basic_ifstreamIcS@GLIBCXX_3.4
1695: 0000003a20055380 40 FUNC GLOBAL DEFAULT 11 _ZNKSt14basic_ifstreamIcS@@GLIBCXX_3.4.5
1731: 0000003a2006bf50 192 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
1808: 0000003a2006bd30 387 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
1897: 0000003a200661e0 5 FUNC WEAK DEFAULT 11 _ZNKSt14basic_ifstreamIcS@@GLIBCXX_3.4
1920: 0000003a2006bbd0 124 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
2003: 0000003a200c4cc0 40 OBJECT WEAK DEFAULT 13 _ZTSSt14basic_ifstreamIcS@@GLIBCXX_3.4
2004: 0000003a20068da0 40 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2079: 0000003a2006c0f0 316 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2085: 0000003a202e7140 80 OBJECT WEAK DEFAULT 21 _ZTVSt14basic_ifstreamIwS@@GLIBCXX_3.4
2124: 0000003a2006b550 387 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
2215: 0000003a202e77c0 24 OBJECT WEAK DEFAULT 21 _ZTISt14basic_ifstreamIcS@@GLIBCXX_3.4
2313: 0000003a2006a710 192 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2419: 0000003a2006bc60 200 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2530: 0000003a20069460 40 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
2635: 0000003a2006bb10 192 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2678: 0000003a2006a4c0 61 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2809: 0000003a202e71a0 32 OBJECT WEAK DEFAULT 21 _ZTTSt14basic_ifstreamIwS@@GLIBCXX_3.4
2828: 0000003a2006a140 42 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
2863: 0000003a2006bec0 124 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
3016: 0000003a2006b930 267 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIwSt@@GLIBCXX_3.4
3109: 0000003a20069cd0 42 FUNC WEAK DEFAULT 11 _ZNSt14basic_ifstreamIcSt@@GLIBCXX_3.4
3149: 0000003a200c4bc0 40 OBJECT WEAK DEFAULT 13 _ZTSSt14basic_ifstreamIwS@@GLIBCXX_3.4

Can anyone help me out? I am baffled why I cannot link a debug version.

You're trying to link to functions:
std::ofstream::open(const std::string &, std::ios);
std::ofstream::ofstream(const std::string &, std::ios);
std::ifstream::ifstream(const std::string &, std::ios);

I didn't know they existed, I thought the signatures were:
std::ofstream::open(const char*, std::ios);
std::ofstream::ofstream(const char*, std::ios);
std::ifstream::ifstream(const char*, std::ios);

I would expect them to exist, but I'm curious as to how they got past the compiler.
Interesting, you're right -- I don't know how this works at all! This code compiles and works perfectly on Windows, but I guess Microsoft helpfully (not) added string versions.

Why does it compile and link without the -O0 -g flags? That's what's so weird.

HALLELUJAH! I updated the code to simply use c_str() where I needed streams and voila, compiled! Thank you so much for your keen eyes, I was completely blind to it.

Doesn't answer why the code links in release, though :).
Topic archived. No new replies allowed.