I'm trying to use CMake to cross compile a C++ code using the Wiring Pi library but I'm having trouble with making CMake to find said the correct library. Since I'm compiling from x86 to ARM in order to run on a Raspberry Pi 2, I assumed I should use the library's ARM format to compile it, but I'm having no success on point the right path to CMake.
Here's my CMakeLists.txt
so far:
set(CMAKE_SYSTEM_NAME Generic)
cmake_minimum_required(VERSION 3.5.1)
project(Project)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
add_compile_options(-march=armv7-a)
set(SOURCES project.cpp ${/home/user1/Documents/wiringpiarm}/libwiringPi.so)
add_executable(Project ${SOURCES})
Just to make clear that the CMakeLists file is in the same directory as project.cpp
, as I'm building it in the build folder.
When I try building it (cmake ..
), I get the following error message:
CMake Error at CMakeLists.txt:11 (add_executable):
Cannot find source file:
//wiringPi.h
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: Project
CMake Error: Cannot determine link language for target "Project".
When I try different alterations on the CMakeLists script, I get other errors like libwiringPi.so
being non existent, or undefined references for some of wiringPi.h
functions like DigitalWrite()
, delay()
, etcetera.
I don't know if I should be using ARM equivalents of libwiringPi.so
or the standard library installed in usr/lib/
; and if using the ARM versions are true, if there's something wrong on my CMakeLists.txt
script. Maybe it's both problems, but I don't have a better idea of what to do at this point.