我在使用CMAKE设置交叉编译时遇到了一些麻烦.我使用的工具链是在yocto中创建的,它在cmake之外完美运行.
我按照教程设置了以下工具链文件:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR arm)
# specify the cross compiler
SET(tools /opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr)
SET(CMAKE_C_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
# set sysroot
SET(CMAKE_SYSROOT /home/sifu/test-yocto/qemuarmdfs)
#SET(CMAKE_FIND_ROOT_PATH /home/sifu/test-yocto/qemuarm)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Run Code Online (Sandbox Code Playgroud)
运行cmake时出现以下错误
The C compiler
"/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec4012536451/fast"
/usr/bin/make …Run Code Online (Sandbox Code Playgroud) 当我尝试构建 googletest(和 googlemock)1.8.0 时,当我尝试与 libgtest.a 链接时,我得到了对 MakeAndRegisterTestInfo 的未定义引用。它适用于具有相同 cmake/make 设置的 1.7.0 版。我想我可以使用 1.7.0,但是我需要单独下载和构建 gmock。
CMakeFiles/unittest.dir/test/test_led.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
test_led.cpp:(.text+0x23d): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/unittest] Error 1
make[1]: *** [CMakeFiles/unittest.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Run Code Online (Sandbox Code Playgroud)
libgtest.a 中的其他符号工作得很好(例如 ::testing::InitGoogleTest),但是一旦我尝试使用宏 TEST_F 添加测试,我就会收到此错误。
这是我的测试用例设置:
#include "gtest/gtest.h"
namespace {
// The fixture for testing (used by TEST_F).
class …Run Code Online (Sandbox Code Playgroud)