TupleCats
TupleCats

Reputation: 351

Cmake: make static library and use in other projects

I need to make library test and use it in other projects by #include <libraryname>

In project test:

CmakeLists.txt

...
add_library(libtest STATIC lib.h lib.cpp)
set_target_properties(libtest PROPERTIES PUBLIC_HEADER lib.h)

install(TARGETS libtest
        PUBLIC_HEADER DESTINATION include
        RUNTIME DESTINATION bin
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib)
...

In project testUseLibrary:

CmakeLists.txt

...
add_executable(project main.cpp)
target_link_libraries(project PUBLIC libtest)
...

main.cpp

#include <libtest> // error 

int main() {
    return 0;
}

In project testUseLibrary #include<libtest> doesn't see library.

Upvotes: 1

Views: 2304

Answers (1)

user3217278
user3217278

Reputation: 350

You need to use target_include_directories to specify the include directories for your target. In this case, the directory where libtest resides.

Upvotes: 0

Related Questions