2

I want to use DirectXTK via vcpkg and link it with my cmake project.

vcpkg.exe list shows the following:

directxtk:x86-windows                              apr2021          A collection of helper classes for writing Direc...
directxtk:x86-windows-static-md                    apr2021          A collection of helper classes for writing Direc...
libzip:x86-windows                                 1.7.3#2          A library for reading, creating, and modifying z...
libzip:x86-windows-static-md                       1.7.3#2          A library for reading, creating, and modifying z...
zlib:x86-windows                                   1.2.11#10        A compression library
zlib:x86-windows-static-md                         1.2.11#10        A compression library

[dependnencies from these are not included here]

You can see that DirectXTK,libzip and zlib is installed.

Now my CMakeLists.txt looks like this:

find_package(ZLIB REQUIRED)
target_link_libraries(Game PRIVATE ZLIB::ZLIB)
if(WIN32)
    find_package(directxtk CONFIG REQUIRED)
    target_link_libraries(Game PRIVATE DirectXTK)
endif()
find_package(libzip REQUIRED)
target_link_libraries(Game PRIVATE libzip)

When I try to compile my project, it says

fatal error LNK1104: cannot open file 'DirectXTK.lib'
fatal error LNK1104: cannot open file 'libzip.lib'

It can't find the lib files for DirectXTK and libzip when linking.
It compiles fine though, which means it can find zlib.h and DirectXTK/WICTextureLoader for example.

How am I supposed to fix that? The cmake Toolchain is correctly set to vcpkg.cmake and I used vcpkg.exe integrate install prior.

Raildex
  • 3,406
  • 1
  • 18
  • 42
  • [DirectXTK wiki](https://github.com/microsoft/DirectXTK/wiki/DirectXTK#cmake) tells that linking with the library is performed via `Microsoft::DirectXTK` target but you link with `DirectXTK` instead. – Tsyvarev Jan 23 '22 at 16:08
  • As for libzip library, its configuration is [installed](https://github.com/nih-at/libzip/blob/master/CMakeLists.txt#L445) with NAMESPACE option equal to `libzip::`, so the proper target to link with is `libzip::zip` (not a `libzip` as in your code). – Tsyvarev Jan 23 '22 at 16:15
  • @Tsyvarev When I use `target_link_libraries(Game PRIVATE Microsoft::DirectXTK)` I receive this error: `Target "Game" links to target "Microsoft::DirectXMath" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? ` – Raildex Jan 23 '22 at 16:21
  • I fixed it by installing DirectXMath and adding `find_packages(directxmath)`, too. Can you make an answer out of your comments? @Tsyvarev – Raildex Jan 23 '22 at 16:43

0 Answers0