2

I have some C code for a library that I'd like to test using googletest. I intend to build the library for multiple architectures including x86, x86-64, ARM and ARM64.

As the library would export some functionality that is architecture specific, I'd like to test the library for each architecture.

In order to test the ARM64 build of the library, I'm trying to compile googletest for ARM64.

googletest uses cmake. I tried using the following cmake script to indicate that I want to cross compile google test.

$ 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

I get the following output :-

-- 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".

Why does this error occur? How can I fix this?

2 Answers 2

4

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)

Command to run cmake

  • /googletest/googletest$ cmake ./ -DCMAKE_TOOLCHAIN_FILE=./toolchain-arm-linux-gnueabihf.cmake
  • /googletest/googletest$ make

command to test the executable type

  • ~/googletest/googletest$ readelf -a -W libgtest_main.a | more
Sign up to request clarification or add additional context in comments.

Comments

2

I've figured it out. Adding the following line fixes the problem.

set(THREADS_PTHREAD_ARG /home/asdf/repos/toolchains/gcc-linaro-6.1.1-2016.08-x86_64_aarch64-linux-gnu/)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.