On Fri, May 13, 2011 at 10:49 PM, Ian Lance Taylor <iant@xxxxxxxxxx> wrote: > Mu Qiao <qiaomuf@xxxxxxxxx> writes: > >> I have a C++ shared library project. When I add "--coverage" to >> CXXFLAGS(I also added -g and -O0) and LDFLAGS, the project fails to >> compile, here's the error message: >> >> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld: >> .libs/variable_printer: hidden symbol `atexit' in >> /usr/lib64/libc_nonshared.a(atexit.oS) is referenced by DSO >> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/bin/ld: >> final link failed: Nonrepresentable section on output >> collect2: ld returned 1 exit status >> make[1]: *** [variable_printer] Error 1 > > The linker message is not very helpful in that it doesn't tell us where > the hidden symbol is referenced from. At a guess, the reference is from > your C++ shared library. You can verify that by using "readelf -r" and > "readelf -s" on the shared library and looking for atexit. If you find > it there as an undefined symbol, then what is the command that you use > to build your shared library? > I find this line in the output of readelf -s: 18447: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND atexit These are the flags I used for compiling: -D_GLIBCXX_DEBUG -std=c++0x -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -Wsign-promo -pedantic-errors -Werror --coverage -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC -DPIC This is the command for linking: libtool: link: g++ -shared -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtbeginS.o src/.libs/libcppbash_la-libbash.o src/.libs/libcppbash_la-cppbash_builtin.o src/builtins/.libs/libcppbash_la-echo_builtin.o src/builtins/.libs/libcppbash_la-source_builtin.o src/builtins/.libs/libcppbash_la-return_builtin.o src/builtins/.libs/libcppbash_la-inherit_builtin.o .libs/libcppbash_la-libbashLexer.o .libs/libcppbash_la-libbashParser.o src/core/.libs/libcppbash_la-interpreter.o src/core/.libs/libcppbash_la-bash_ast.o -Wl,--whole-archive ./.libs/libwalker.a -Wl,--no-whole-archive -lantlr3c -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/../../../../lib64/crtn.o --coverage -Wl,-soname -Wl,libcppbash.so.0 -o .libs/libcppbash.so.0.0.0 I googled and some people say that -nostdlib in the linking command caused the problem. But the command is run by libtool. I don't know what to do with it except applying a patch. >> I tried with >> "configure --disable-shared" and it worked for us. But I don't know >> the reason of the above error and can't be sure if --disable-shared is >> the correct solution. > > Which configure script do you mean here? The gcc configure script or > yours? > I mean my configure script. "configure --diable-shared" works fine on both 32bit and 64bit machine. -- Best wishes, Mu Qiao GnuPG fingerprint: 92B1 B0C4 8D14 F8C4 EFA5 3ACC 30B3 0DE4 17B1 57E9