我有一些我想用googletest测试的库的C代码。我打算为多种架构构建库,包括x86,x86-64,ARM和ARM64。
由于库将导出一些特定于体系结构的功能,我想为每个体系结构测试库。
为了测试库的ARM64版本,我正在尝试为ARM64编译googletest。
googletest使用cmake。我尝试使用以下cmake脚本来表明我想要交叉编译谷歌测试。
$ cat toolchain-arm64.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CXX_COMPILER /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)
set(CMAKE_C_COMPILER /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
set(CMAKE_FIND_ROOT_PATH /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
$ mkdir build && cd build
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm64.cmake
我得到以下输出: -
-- The CXX compiler identification is GNU 6.1.1
-- The C compiler identification is GNU 6.1.1
-- Check for working CXX compiler: /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.12")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
THREADS_PTHREAD_ARG (advanced)
For details see /home/asdf/repos/misc/googletest/googletest/build/TryRunResults.cmake
-- Check if compiler accepts -pthread - no
-- Found Threads: TRUE
-- Configuring incomplete, errors occurred!
See also "/home/asdf/repos/misc/googletest/googletest/build/CMakeFiles/CMakeOutput.log".
See also "/home/asdf/repos/misc/googletest/googletest/build/CMakeFiles/CMakeError.log".
为什么会出现此错误?我该如何解决这个问题?
答案 0 :(得分:1)
我已经弄明白了。添加以下行可以解决问题。
set(THREADS_PTHREAD_ARG /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/)
答案 1 :(得分:1)
cat googlemock / toolchain-arm-linux-gnueabihf.cmake
# Target system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabihf)
# Cross compiler
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
# Search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# 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)
set(THREADS_PTHREAD_ARG "0" CACHE STRING "Result from TRY_RUN" FORCE)