In a first step I created a test.dll
library with the corresponding import library test.dll.a
and the header file test.h
. I build a new "client" project where I want to use this created library.
I have the following file structure:
client
│ └── CMakeLists.txt
|── src
│ ├── main.cpp
│ └── CMakeLists.txt
├── lib
│ ├── test.dll
│ └── libtest.dll.a
│ └── test.h
In the root CmakeLists.txt
I wanted to add the library
cmake_minimum_required(VERSION 3.6)
project(client)
add_subdirectory(lib)
add_library(test SHARED IMPORTED GLOBAL)
set_target_properties(
test
PROPERTIES
IMPORTED_LOCATION /path/client/lib/test.dll
IMPORTED_IMPLIB /path/client/lib/libtest.dll.a
)
add_subdirectory(src)
And in the src CmakeLists.txt
file I wrote:
add_executable(main main.cpp)
target_link_libraries(main PRIVATE test)
In the client main.cpp
I included the library via #include "test.h"
.
With that I get the error message: test.h: No such file or directory
and cannot open source file test.h
.
Does somebody know how to add the DLL correctly to the cmake project?
The property INTERFACE_INCLUDE_DIRECTORIES
need to be added to the test target.
set_target_properties(
test
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES /path/client/lib
IMPORTED_LOCATION /path/client/lib/test.dll
IMPORTED_IMPLIB /path/client/lib/libtest.dll.a
)
NB: The add_subdirectory(lib)
command can be safely removed, as you did not place a CMakeLists.txt file there and nothing needs to be built inside this dir.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments