0

I have a library in: C:\vcpkg\installer\x86-windows-static\lib and I would like to link it via this absolute path.

The cmake file resides elsewhere, it is for an executable program (not a library).

Is it possible to link for example example_lib.lib from this absolute path?

Everywhere I read it's just about building the library, but I just want to link on it, .lib specifically.

pman
  • 33
  • 9
  • With CMake and vcpkg you should use the toolchain file when you configure for your application with CMake and not care about the exact path of the library. This answer discusses how to do that: [https://stackoverflow.com/a/59251091/487892](https://stackoverflow.com/a/59251091/487892) – drescherjm Jan 09 '23 at 21:16

1 Answers1

0

The CMakes target_link_libraries() allows you to specify the library via an absolute path.

Milan Š.
  • 1,353
  • 1
  • 2
  • 11
  • Which doesn't work, for example: `target_link_libraries(my_program PUBLIC C:/vcpkg/installed/x86-windows-static/lib/example_lib.lib)` gives `/user/bin/ld: cannot find -lC:/vcpkg/installed/x86-windows-static/lib/example_lib.lib` Yes "example_lib.lib" exists in that path, I just name it as such for example – pman Jan 09 '23 at 20:36
  • You are most likely linking a x64 binary against x86 (32bit) binaries. Which you can't do. Update the triplets that you pull from vcpkg to 64bit triplets and it will work. – Milan Š. Jan 09 '23 at 20:38
  • https://learn.microsoft.com/en-us/vcpkg/users/triplets – Milan Š. Jan 09 '23 at 20:39
  • @pman let me know if you need any more help. – Milan Š. Jan 09 '23 at 20:57
  • I installed the x64 version, and modified the absolute path in `target_link_libraries`, but unfortunately I still get the same issue (the lib can't be found) – pman Jan 09 '23 at 20:59
  • 1
    @pman which compiler are you using? If you are using Mingw32 then the standard vcpkg triplets are for MSVC. vcpkg repositories do contain mingw32 triplets but you have to specify it (yet again) EDIT: or mingw64 – Milan Š. Jan 09 '23 at 21:03
  • I am judging this based on `user/bin/ld` – Milan Š. Jan 09 '23 at 21:04
  • https://vcpkg.io/en/docs/users/mingw.html – Milan Š. Jan 09 '23 at 21:05
  • I am running cmake from wsl, so I'd suppose my compiler identification is GNU 9.4.0 I created a new project and built a 64-bit library. Specifying the absolute path to it still results in the same error. Maybe ignore the fact it's vcpkg, I should be able to link arbitrary .lib file from any path (but seems like this is not doable...) – pman Jan 09 '23 at 21:14
  • 2
    Nothing created in `C:\vcpkg\installer\x86-windows-static\lib` should be correct for WSL. You are mixing compilers and operating systems. – drescherjm Jan 09 '23 at 21:23
  • 2
    Exactly as @drescherjm stated. You need binaries created by the exact same compiler. Otherwise they will be different and result in such errors. If you wish to cross-compile from linux to windows it is possible, but it is for a much longer discussion. The issue is in my eyes resolved. To compile on WSL just get the packages from the standard package manager the distribution provides. But bare in mind that you will be (unless you crosscompile) compiling for Linux. – Milan Š. Jan 09 '23 at 21:29
  • 1
    As a general recommendation for future questions. I would start by describing what you are using and on what system (setup) you are working. Debugging such issues will become faster. For now I recommend ditching WSL, because the tools you wish to use are available on Windows. – Milan Š. Jan 09 '23 at 21:30