背景
交叉编译代码,很多链接库都是手动指定的,编译的代码中存在部分测试代码,需要gtest和gmock的支持。
问题
交叉编译test代码的时候,出现了报错
bin/ld: static-reloc.c:(.text+0x24): undefined reference to `main'
解决方案
手动指定链接库的时候:
- gtest库需要同时添加 libgtest.a 和 libgtest_main.a
- gmock库需要同时添加 libgmock.a 和 libgmock_main.a
如:
set(GTEST_LIBRARIES "/path/to/libgtest_main.a"
"/path/to/libgtest.a")
set(GTEST_INCLUDE_DIRS "/path/to/gtest/include")
set(