Link to a dynamic link library in a cmake project

Suslik

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?

vre

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use dynamic link library with CMake?

From Dev

Need to link cmake project to dl library

From Dev

Link error with SFML library in CMake project on Windows

From

CMake link to external library

From Dev

Link to static library by cmake

From Dev

Link library OpenSubdiv with CMake

From Dev

Dynamic link library in C

From Dev

CMake link library from subdirectory

From Dev

CMake link shared library on Windows

From Dev

CMake cannot link library correctly

From Dev

How to link library using cmake

From Dev

cmake link executable and aalib library

From Dev

Unable to link dynamic library in macOS

From Dev

Pass function to dynamic link library

From Dev

CMake Project structure: When to use add_library/target_link_library over target_sources?

From Dev

Link native library to Android project

From Dev

How to link a third-party static library with the newly created cmake project?

From Dev

How to build TensorFlow Lite as a static library and link to it from a separate (CMake) project?

From Dev

How to link C++17 stdc++fs library to mixed language (C++ and Fortran) CMake project?

From Dev

Cannot get cmake to link to GLFW library

From Dev

How to link a library generated by cmake on other directory?

From Dev

How do I link a library using CMake?

From Dev

link to pthread library using CMake (in CLion)

From Dev

CMAKE link shared library that has version information

From Dev

CMake failing to link Boost regex library in Clion

From Dev

How to link to the C math library with CMake?

From Dev

Cmake: How to statically link packages to shared library?

From Dev

How to link a shared library with CMake with relative path

From Dev

How to link shared library *dll with CMake in Windows

Related Related

  1. 1

    How to use dynamic link library with CMake?

  2. 2

    Need to link cmake project to dl library

  3. 3

    Link error with SFML library in CMake project on Windows

  4. 4

    CMake link to external library

  5. 5

    Link to static library by cmake

  6. 6

    Link library OpenSubdiv with CMake

  7. 7

    Dynamic link library in C

  8. 8

    CMake link library from subdirectory

  9. 9

    CMake link shared library on Windows

  10. 10

    CMake cannot link library correctly

  11. 11

    How to link library using cmake

  12. 12

    cmake link executable and aalib library

  13. 13

    Unable to link dynamic library in macOS

  14. 14

    Pass function to dynamic link library

  15. 15

    CMake Project structure: When to use add_library/target_link_library over target_sources?

  16. 16

    Link native library to Android project

  17. 17

    How to link a third-party static library with the newly created cmake project?

  18. 18

    How to build TensorFlow Lite as a static library and link to it from a separate (CMake) project?

  19. 19

    How to link C++17 stdc++fs library to mixed language (C++ and Fortran) CMake project?

  20. 20

    Cannot get cmake to link to GLFW library

  21. 21

    How to link a library generated by cmake on other directory?

  22. 22

    How do I link a library using CMake?

  23. 23

    link to pthread library using CMake (in CLion)

  24. 24

    CMAKE link shared library that has version information

  25. 25

    CMake failing to link Boost regex library in Clion

  26. 26

    How to link to the C math library with CMake?

  27. 27

    Cmake: How to statically link packages to shared library?

  28. 28

    How to link a shared library with CMake with relative path

  29. 29

    How to link shared library *dll with CMake in Windows

HotTag

Archive