I'm trying to set up a cross-compile flow targeting Raspberry Pi from a Linux Ubuntu VirtualBox install. I cloned the tool repo (as opposed to setting up a full crosstool-ng build) and am able to compile a basic hellow world app and run it on my pi. I'm now trying to get more complicated example going by compiling the wiringpi library through my cross-compile flow through cmake, following this tutorial: https://medium.com/@au42/the-useful-raspberrypi-cross-compile-guide-ea56054de187
Unfortunately, it's not working - I'm getting compile errors due to undeclared functions, which look like standard C libraries (time.h). The first c files (softpwm.c) compiles relatively easily, but the second (wiringPi.c) errors because it includes time.h - and refers to constants defined within.
Near as I can tell, the cross-compiled version of gcc is not looking into appropriate directories for system library headers (usr/include/ linux|sys|bits). I've verified that time.h does indeed reside within the sysroot path specified by my toolchain file passed to cmake.
I've not written any code here mind you, I'm merely trying to reproduce this tutorial which builds a cross-compiled version of WiringPi using a cross-compile tool chain.
I've attempted to add specific include directories underneath in my CMakeLists.txt file, but this creates other compile errors. The first library fails to build as now it's unable to find the pthreads package.
I have also successfully build a GNU example using basic time.h using my cross-compile flow to see if there is a problem with the tool installation. This worked compiled fine.
I've turned on verbose makefile, -v, and -Wall options in an effort to understand what is going on, and what might be missing.
cmake . -DCMAKE_TOOLCHAIN_FILE=Toolchain-rpi.cmake
make
And my Toolchain-rpi.cmake file:
# Define our host system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(PITOOL "/home/greg/sanitaslabs/cacheq/raspi/tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf")
#set(SYSROOT "${PITOOL}/arm-linux-gnueabihf/sysroot")
set(SYSROOT "${PITOOL}/arm-linux-gnueabihf/sysroot")
# Define the cross compiler locations
#SET(CMAKE_C_COMPILER /home/greg/sanitaslabs/cacheq/raspi/tools/arm-
bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_C_COMPILER ${PITOOL}/bin/arm-linux-gnueabihf-gcc)
#SET(CMAKE_CXX_COMPILER
/home/greg/sanitaslabs/cacheq/raspi/tools/arm-bcm2708/arm-rpi-4.9.3-
linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${PITOOL}/bin/arm-linux-gnueabihf-g++)
# Define the sysroot path for the RaspberryPi distribution in our
tools folder
#SET(CMAKE_FIND_ROOT_PATH ${SYSROOT})
# Use our definitions for compiler tools
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories only
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
add_definitions(-v -Wall -std=c11)
Error:
/home/greg/sanitaslabs/cacheq/raspi/wiringPi/wiringPi/wiringPi.c:2058:3: warning: implicit declaration of function 'clock_gettime' [-Wimplicit-function-declaration]
clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ;
^
/home/greg/sanitaslabs/cacheq/raspi/wiringPi/wiringPi/wiringPi.c:2058:18: error: 'CLOCK_MONOTONIC_RAW' undeclared (first use in this function)
clock_gettime (CLOCK_MONOTONIC_RAW, &ts) ;
^