0

I would like to add library wiringPi.h to my Makefile in cmake, but cmake doesn't see this header.

cmake_minimum_required(VERSION 2.8)
project( program )
include_directories(include)
find_package( OpenCV REQUIRED )
add_executable( program program.cpp )
target_link_libraries( program ${OpenCV_LIBS} ) 

The project organization is:

|-- CMakeLists.txt
|
|-- program.cpp
|
|-- wiringPi.h

How should I add this header to Makefile?

Luko
  • 9
  • 1
  • 1
    You don't need to add headers. CMake figures them out by itself. – usr1234567 Dec 06 '16 at 18:19
  • @Stargateur I dumped add_executable( program program.cpp ) and I try your way and it doesn't work /home/luko/naukacop/program.cpp:2:22: fatal error: wiringPi.h: No such file or directory compilation terminated. CMakeFiles/program.dir/build.make:62: recipe for target 'CMakeFiles/program.dir/program.cpp.o' failed make[2]: *** [CMakeFiles/program.dir/program.cpp.o] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/program.dir/all' failed make[1]: *** [CMakeFiles/program.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2 – Luko Dec 06 '16 at 18:24
  • `cmake_minimum_required(VERSION 2.8) project( program ) include_directories(wiringPi) add_executable(wiringPi lukasz22/naukacop/wiringPi.h ) find_package( OpenCV REQUIRED ) add_executable( program program.cpp wiringPi.h) target_link_libraries( program ${OpenCV_LIBS} ) ` @Stargateur Is it correct? I get some errors :( – Luko Dec 06 '16 at 18:51
  • @Stargateur Sorry, today I started using Stackoverflow. `CMake Error at CMakeLists.txt:4 (add_executable): Cannot find source file: luko/naukacop/wiringPi.h Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx ' – Luko Dec 06 '16 at 19:05
  • Yes, I used tree, but my library is in folder, but I see my library only in CMakeFiles – Luko Dec 06 '16 at 19:14
  • @Stargateur Thanks for your time and help [here](http://iv.pl/images/06202576525838325994.jpg) -> That's the tree – Luko Dec 06 '16 at 20:23

1 Answers1

0

This must work in your case:

cmake_minimum_required(VERSION 2.8)
project(program)
find_package(OpenCV REQUIRED)
add_executable(program program.cpp wiringPi.h)
target_link_libraries(program ${OpenCV_LIBS})

If you need more information read this How to properly add include directories with CMake?. You should read the official tuto. Be aware that 2.8 is a very old version, you should update to the latest stable.

Community
  • 1
  • 1
Stargateur
  • 24,473
  • 8
  • 65
  • 91