Googletest: 'make check' fails with undefined references.

Created on 28 Jul 2015  路  8Comments  路  Source: google/googletest

What steps will reproduce the problem?
1. ./configure
2. make
3. make check


What is the expected output? What do you see instead?

When running 'make check', I expect to see a successful build, followed by all 
tests passing.  
Instead, I see this:
make  samples/sample1_unittest samples/sample2_unittest 
samples/sample3_unittest 
samples/sample4_unittest samples/sample5_unittest samples/sample6_unittest 
test/gtest_unittest test/gtest-death-test_test test/gtest-filepath_test 
test/gtest-message_test 
test/gtest-options_test test/gtest_pred_impl_unittest 
test/gtest_environment_test 
test/gtest_no_test_unittest test/gtest_main_unittest test/gtest_prod_test 
test/gtest_repeat_test 
test/gtest_stress_test test/gtest-typed-test_test  
make[1]: Entering directory `/home/pberry/gtest/gtest-1.1.0'
depbase=`echo samples/sample1_unittest.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`; \
if g++ -DHAVE_CONFIG_H -I. -I. -I./config_aux  -I. -I./include   -g -O2 -MT 
samples/sample1_unittest.o -MD -MP -MF "$depbase.Tpo" -c -o 
samples/sample1_unittest.o 
samples/sample1_unittest.cc; \
then mv -f "$depbase.Tpo" "$depbase.Po"; else rm -f "$depbase.Tpo"; exit 1; fi
/bin/sh ./libtool --tag=CXX --mode=link g++  -g -O2   -o 
samples/sample1_unittest  
samples/sample1_unittest.o lib/libgtest_main.la samples/libsamples.la 
g++ -g -O2 -o samples/.libs/sample1_unittest samples/sample1_unittest.o  
lib/.libs/libgtest_main.so samples/.libs/libsamples.a -Wl,--rpath 
-Wl,/usr/local/lib
samples/sample1_unittest.o(.text+0x1303): In function `global constructors 
keyed to 
_ZN27FactorialTest_Negative_Test10test_info_E':
./include/gtest/internal/gtest-internal.h:484: undefined reference to 
`testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char 
const*, char const*, 
void*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
samples/sample1_unittest.o(.text+0x134d):./include/gtest/internal/gtest-internal
.h:484: 
undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, 
char const*, 
char const*, char const*, void*, void (*)(), void (*)(), 
testing::internal::TestFactoryBase*)'
samples/sample1_unittest.o(.text+0x1397):./include/gtest/internal/gtest-internal
.h:484: 
undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, 
char const*, 
char const*, char const*, void*, void (*)(), void (*)(), 
testing::internal::TestFactoryBase*)'
samples/sample1_unittest.o(.text+0x13e1):./include/gtest/internal/gtest-internal
.h:484: 
undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, 
char const*, 
char const*, char const*, void*, void (*)(), void (*)(), 
testing::internal::TestFactoryBase*)'
samples/sample1_unittest.o(.text+0x142b):./include/gtest/internal/gtest-internal
.h:484: 
undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, 
char const*, 
char const*, char const*, void*, void (*)(), void (*)(), 
testing::internal::TestFactoryBase*)'
samples/sample1_unittest.o(.text+0x1475):./include/gtest/internal/gtest-internal
.h:484: more 
undefined references to `testing::internal::MakeAndRegisterTestInfo(char 
const*, char const*, 
char const*, char const*, void*, void (*)(), void (*)(), 
testing::internal::TestFactoryBase*)' follow
collect2: ld returned 1 exit status
make[1]: *** [samples/sample1_unittest] Error 1
make[1]: Leaving directory `/home/pberry/gtest/gtest-1.1.0'
make: *** [check-am] Error 2


What version of the product are you using? On what operating system?

I am using version 1.1.0 on an AMD Opteron 285.  The OS is RedHat 4 update 1.  
Here is the 
result of 'uname -a':
Linux sim12 2.6.9-42.0.10.ELsmp #1 SMP Fri Feb 16 17:13:42 EST 2007 x86_64 
x86_64 x86_64 
GNU/Linux

And here is the result of gcc --version:
gcc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.1)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Please provide any additional information below.



Original issue reported on code.google.com by [email protected] on 14 Oct 2008 at 4:09

Priority-Low Type-Defect auto-migrated

Most helpful comment

OK, I found out the reason:

  1. If you installed gtext to system-wide and pass -I/opt/local/include or -I/usr/include before the local include, the cmake first build the object file with the system gtest lib
  2. the second step, cmake build the executable with the .a file (not the system one), hence the error occurs.

So here is the solution for cmake users:

include_directories(BEFORE ${GTEST_INCLUDE_DIRS})

All 8 comments

We couldn't repro it on our machines.

This looks like you are linking with an old version of gtest.  Perhaps you 
didn't 
clean up the build after you upgraded to 1.1.0.  Please try 'make clean' first. 

Better yet, try a fresh copy of gtest 1.2.0.

Original comment by [email protected] on 2 Dec 2008 at 4:57

  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

Original comment by [email protected] on 2 Dec 2008 at 5:01

  • Changed state: Accepted
No response from the reporter.

Original comment by [email protected] on 22 Feb 2009 at 5:24

  • Changed state: WontFix

I have the same problem, here is my output:

cd /Users/c9s/work/c6/tests && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/c6_options_test.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -std=c++11 -arch x86_64 -stdlib=libc++ -Wall -Wno-long-long -Wno-unused-value -Wno-overloaded-virtual -pg -O0 -g3 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/c6_options_test.dir/c6_options_test.cc.o CMakeFiles/c6_options_test.dir/main.cc.o  -o c6_options_test  -L/Users/c9s/work/c6/vendor/gflags  -L/Users/c9s/work/c6/vendor/glog  -L/opt/local/lib  -lpthread ../vendor/gtest/libgtest.a ../vendor/gtest/libgtest_main.a -Wl,-rpath,/Users/c9s/work/c6/vendor/gflags -Wl,-rpath,/Users/c9s/work/c6/vendor/glog -Wl,-rpath,/opt/local/lib
Undefined symbols for architecture x86_64:
  "testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
      ___cxx_global_var_init in c6_options_test.cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/c6_options_test] Error 1
make[1]: *** [tests/CMakeFiles/c6_options_test.dir/all] Error 2
make: *** [all] Error 2

I have to add "-lgtest" library to make it work:

target_link_libraries(c6_options_test
    pthread
    gtest
    ${GTEST_BOTH_LIBRARIES}
    ${Boost_LIBS})

OK, I found out the reason:

  1. If you installed gtext to system-wide and pass -I/opt/local/include or -I/usr/include before the local include, the cmake first build the object file with the system gtest lib
  2. the second step, cmake build the executable with the .a file (not the system one), hence the error occurs.

So here is the solution for cmake users:

include_directories(BEFORE ${GTEST_INCLUDE_DIRS})

@c9s

So here is the solution for cmake users:

.cmake include_directories(BEFORE ${GTEST_INCLUDE_DIRS})

Thank you. It works!

Just found in 1.8.1 the same bug.
Is that bug already have been fixed an committed? If yes may I ask for URL to the commit?
And if not may I ask for actual patch with the fix?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ElectricRCAircraftGuy picture ElectricRCAircraftGuy  路  4Comments

qiuxin picture qiuxin  路  5Comments

cyberdecker picture cyberdecker  路  3Comments

GoogleCodeExporter picture GoogleCodeExporter  路  5Comments

markfrazzetto picture markfrazzetto  路  3Comments