简体   繁体   中英

CMAKE include_directories

I am trying to link my library with some other library lib1 using CMAKE 2.8 . It should be said it's 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 compiler says that some #include <lib1/foo.h> in my library is unresolved, maybe because there is no -I.../lib1/include command-line parameter for gcc .

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

Check the following:

  1. Does the path ${CMAKE_SOURCE_DIR}/lib1/include/lib1/foo.h exist?

  2. Quote ( " ) the path passed to include_directories , otherwise you may be passing several paths when it is split by spaces

  3. Try running make VERBOSE=1 to see exactly what options are being passed to gcc

Try to move include_directories() invokation before add_library.

add_library() instructs CMake to compile your sources into library using current set of compiler flags. Altering these flags after compiling do not have any effect. CMake language is not declarative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM