Cross Compile of WiringPi library












1















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) ;
^









share|improve this question

























  • try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

    – Fred
    Jan 2 at 0:51
















1















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) ;
^









share|improve this question

























  • try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

    – Fred
    Jan 2 at 0:51














1












1








1








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) ;
^









share|improve this question
















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) ;
^






gcc cmake raspberry-pi cross-compiling wiringpi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 0:48









Stephen Newell

3,98111721




3,98111721










asked Jan 2 at 0:19









soyAnarchistosoyAnarchisto

61




61













  • try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

    – Fred
    Jan 2 at 0:51



















  • try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

    – Fred
    Jan 2 at 0:51

















try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

– Fred
Jan 2 at 0:51





try compiling with -save-temps. This will generate a .i file and you can inspect it to see which header files are included. It could help to determine if the correct time.h file is used.

– Fred
Jan 2 at 0:51












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999993%2fcross-compile-of-wiringpi-library%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999993%2fcross-compile-of-wiringpi-library%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith