shaobozi / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

I put my tests in a library and Google Test doesn't run them - GCC 4.8 #481

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have the reference project at https://github.com/tinkerbeast/myJunk.

Just do:

    mkdir build
    cd build
    cmake ../
    make
    ./run_tests

This does not execute any test cases in my local environment. This seemed to 
work on travis-ci.org, so I was wondering if this is some GCC / environmental 
issue. My GCC is:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' 
--with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs 
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.8 --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls 
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug 
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap 
--enable-plugin --with-system-zlib --disable-browser-plugin 
--enable-java-awt=gtk --enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic 
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 

Original issue reported on code.google.com by rishin.g...@gmail.com on 5 Dec 2014 at 6:20

GoogleCodeExporter commented 9 years ago
Make sure the *_test libraries are actually linked into the final binary.
The linker might be excluding them because you are not using any symbol from it 
on you main file.
See 
https://code.google.com/p/googletest/wiki/Primer#Important_note_for_Visual_C++_u
sers
That is for VC++, but it applies to gcc also. I think --whole-archive can be 
used for gcc to force the library to be linked.

Original comment by sbe...@google.com on 5 Dec 2014 at 7:33

GoogleCodeExporter commented 9 years ago
You were right: The *_test libraries weren't linked to the final binary. It 
wasn't a CMake specific error, GCC just won't link unreferenced libraries. The 
--whole-archive flag doesn't work either - You have to use --no-as-needed. 

Thanks for all your help. I'll probably introduce fake dependencies to make it 
work in a cleaner way.

Shouldn't this information be added in the FAQ? Anybody upgrading to the newer 
compiler should face this.

Original comment by rishin.g...@gmail.com on 6 Dec 2014 at 7:27

GoogleCodeExporter commented 9 years ago

Original comment by sbe...@google.com on 8 Dec 2014 at 2:47