[solved] I am coding in a Raspberry Pi and I am having some trouble combining code that uses OpenCV and pigpio libraries in c++. I have some code that uses OpenCV that is compiled with CMake, and other code that uses pigpio compiled with g++. I am not able to get the OpenCV library work with g++, and i cant figure out how to add the pigpio library to the CMakeLists.
I dont know if it is possible to add the -lpigpio to the CMakeLists
g++ -Wall -pthread -o pigpio pigpio.cpp -lpigpio
I have tried creating a Findpigpio.cmake copying this https://github.com/joan2937/pigpio/blob/master/util/Findpigpio.cmake
and adding it to /usr/share/cmake-3.6/Modules, then creating a CMakeLists.txt with the following:
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
project(pigpio1_project)
find_package(pigpio REQUIRED)
include_directories(${pigpio_INCLUDE_DIRS})
add_executable(pigpio1 pigpio1.cpp)
target_link_libraries(pigpio1 LINK_PRIVATE ${pigpio_LIBS})
but when doing "cmake .. && make" it shows me the following error:
Scanning dependencies of target pigpio1
[ 50%] Building CXX object CMakeFiles/pigpio1.dir/pigpio1.cpp.o
[100%] Linking CXX executable pigpio1
CMakeFiles/pigpio1.dir/pigpio1.cpp.o: In function `main':
pigpio1.cpp:(.text+0x1c): undefined reference to `gpioInitialise'
pigpio1.cpp:(.text+0x64): undefined reference to `gpioServo'
pigpio1.cpp:(.text+0x70): undefined reference to `gpioServo'
pigpio1.cpp:(.text+0x84): undefined reference to `gpioServo'
pigpio1.cpp:(.text+0x90): undefined reference to `gpioServo'
collect2: error: ld returned 1 exit status
CMakeFiles/pigpio1.dir/build.make:94: recipe for target 'pigpio1' failed
make[2]: *** [pigpio1] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pigpio1.dir/all' failed
make[1]: *** [CMakeFiles/pigpio1.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I could make it work in Cmake (thanks to the comment of tsyvarev) I wasnt using the right name of the pigpio library variable.