I'm trying to compile a unit testing target using googletest. While it works in one project, it is failing to link in a different project, and I'm struggling to understand why.
The link.txt
generated by CMake:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -stdlib=libc++ -std=gnu++11 -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/runTests.dir/ATAppTests.cpp.o -o runTests ../../src/targetLib.a ../../lib/libgtestd.a ../../lib/libgtest_maind.a ../../lib/libgmockd.a ../../lib/libgmock_maind.a ../../lib/libgmockd.a ../../lib/libgtestd.a
The result of running that command:
Undefined symbols for architecture x86_64:
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
___cxx_global_var_init in ATAppTests.cpp.o
However, running nm
indicates the symbol is there:
$ nm --demangle ../../lib/libgtestd.a | grep 'MakeAndRegister'
000000000000ebe0 T testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)
I'm not sure where to go from here!
It turns out another project I am using has an old gtest header embedded in it, which was being picked up instead.