gcc链接器失败,.a文件和gtest

时间:2018-07-28 13:22:04

标签: c++ gcc makefile linker ld

我的makefile条目是:

tests: testLib.a $(CC) testLib.a -o tests /usr/lib/libgtest.a /usr/lib/libgtest_main.a -lpthread -Iinclude $(LD_FLAGS) $(CC_FLAGS)

testLib.a是使用(当前)单个.o文件进行归档创建的,带有通过makefile条目创建的测试: testLib.a: test_obj $(TEST_OBJ_FILES) ar rvs testLib.a $(TEST_OBJ_FILES)

我收到gtest的链接器错误: /usr/lib/libgtest_main.a(gtest_main.cc.o): In function `main': gtest_main.cc:(.text+0x28): undefined reference to `testing::InitGoogleTest(int*, char**)' /usr/lib/libgtest_main.a(gtest_main.cc.o): In function `RUN_ALL_TESTS()': gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x5): undefined reference to `testing::UnitTest::GetInstance()' gtest_main.cc:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0xd): undefined reference to `testing::UnitTest::Run()' collect2: error: ld returned 1 exit status

但是当我将testLib.a更改为单个.o文件时,一切都可以正常编译: tests: testLib.a $(CC) test_obj/singleTestFile.o -o tests /usr/lib/libgtest.a /usr/lib/libgtest_main.a -lpthread -Iinclude $(LD_FLAGS) $(CC_FLAGS)

我的条目无法使用自己创建的归档文件怎么办? ar从$(TEST_OBJ_FILES)正确获取文件: ar rvs testLib.a test_obj/singleTestFile.o

0 个答案:

没有答案