CMAKE include_directories

I am trying to link my library with another lib1 library using CMAKE 2.8 . This should be said on Windows.

In CMakeLists.txt , I have:

 add_library(mylib ${sources}) include_directories(${CMAKE_SOURCE_DIR}/lib1/include) target_link_libraries(mylib ${lib1_path}) 

But the compiler says that some #include <lib1/foo.h> in my library has not been resolved, possibly because for gcc there is no command-line option -I.../lib1/include .

UPDATE It should be said that the compiler complains when compiling TESTS is not mylib .

+6
source share
2 answers

Check the following:

  • Is there a path of ${CMAKE_SOURCE_DIR}/lib1/include/lib1/foo.h ?

  • Quote ( " ) path passed to include_directories , otherwise you can pass multiple paths when it breaks into spaces

  • Try running make VERBOSE=1 to see what parameters are passed to gcc

+9
source

Try moving include_directories() invokation before add_library.

add_library() instructs CMake to compile your sources into a library using the current set of compiler flags. Changing these flags after compilation has no effect. CMake is not declarative.

+7
source

Source: https://habr.com/ru/post/901876/


All Articles