Learning cmake for use with CLion. I have a raspberry pi project and I'm trying to bring in wiringPi library on my Ubuntu box. Here's my build results.

====================[ Build | rookery_exe | Raspberry Pi Release ]==============
/snap/bin/cmake --build /tmp/tmp.UNnm1OGKQ2/cmake-build-raspberry-pi-release --target rookery_exe -- -j 12
[  9%] Building CXX object src/core/CMakeFiles/rookery_core.dir/Lights.cpp.o
/tmp/tmp.UNnm1OGKQ2/src/core/Lights.cpp:1:10: fatal error: wiringPi.h: No such file or directory
    1 | #include <wiringPi.h>
      |          ^~~~~~~~~~~~
compilation terminated.
gmake[3]: *** [src/core/CMakeFiles/rookery_core.dir/build.make:124: src/core/CMakeFiles/rookery_core.dir/Lights.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:203: src/core/CMakeFiles/rookery_core.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:236: src/exe/CMakeFiles/rookery_exe.dir/rule] Error 2
gmake: *** [Makefile:182: rookery_exe] Error 2

I installed both libwiringpi and libwiringpi-dev. When I looked, here's the result of my find command:

thomas@bravos:/usr$ find -name *wiringPi*

My cmake file is as follows:

cmake_minimum_required(VERSION 3.19)






target_include_directories(${CMAKE_PROJECT_NAME}_core PUBLIC /usr/include ${CMAKE_CURRENT_SOURCE_DIR} )

target_link_directories(${CMAKE_PROJECT_NAME}_core INTERFACE /usr/lib/x86_64-linux-gnu)

find_library(LIB_WIRING_PI libwiringPi HINTS /usr/lib/x86_64-linux-gnu)

Not sure where to go with this. I took a whole udemy class on cmake.

  • Could you edit your post and indicate the result of compiling a minimal wiringPi program with gcc? It just needs to be dummy main as long as the source includes wiringPi.h.
    – joan
    Commented May 27, 2021 at 10:03
  • @joan, You mean cross compiling or compiling on the raspberry pi itself?
    – Thom
    Commented May 27, 2021 at 11:07
  • On your Ubuntu box. The same as your cmake. I'm just wondering why the include is not found in your path.
    – joan
    Commented May 27, 2021 at 11:11
  • @joan I have such a program. I'll have to figure out how to build without cmake. Do you have advice? Can I find the build command somewhere in my makefile?
    – Thom
    Commented May 27, 2021 at 11:20

1 Answer 1


You have installed WiringPi in your Ubuntu machine's /usr folder. CMake doesn't look in /usr/lib/x86_64-linux-gnu or /usr/include when cross-compiling, and it shouldn't look there either.

You have to install WiringPi in the sysroot folder you created for cross-compiling.

I took a whole udemy class on cmake.

If that course teaches people to GLOB_RECURSE the source files or to hard-code system paths like /usr/include, you might want to forget what you learned there ...

  • Those are things I've tried on my own to get this working. By sysroot folder, is that the toolchain folder I created that holds the cross compiler?
    – Thom
    Commented May 27, 2021 at 16:08
  • @Thom no, the sysroot is the folder that contains all necessary libraries and headers for cross compilation. Your toolchain comes with a basic sysroot that has glibc etc. Your toolchain's sysroot is (should be) read-only, so you usually create a copy that you install all libraries into for a specific project. From your previous questions, I understand that you are using my RPi-Cpp-Toolchain, it has a brief explanation about sysroots here: tttapa.github.io/Pages/Raspberry-Pi/C++-Development/…
    – tttapa
    Commented May 27, 2021 at 16:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.