Vcpkg: How do I use my own lib instead of system libs

Created on 10 Sep 2020  路  10Comments  路  Source: microsoft/vcpkg

Hi,
I'd like to use my own built libs instead of the system's one by default.
I saw in scripts/buildsystems/vcpkg.cmake(L221) this:

...
if(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$" OR NOT DEFINED CMAKE_BUILD_TYPE) #Debug build: Put Debug paths before Release paths.
    list(APPEND CMAKE_PREFIX_PATH
        ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
    )
    list(APPEND CMAKE_LIBRARY_PATH
        ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib/manual-link ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/manual-link
    )
    list(APPEND CMAKE_FIND_ROOT_PATH
        ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
    )
...

The append directive bothers me because the system lib is found before my own on MacOS. (ZLib)
(System lib): /usr/lib/libz.tbd
(My lib): /tmp/test/vcpkg/x86-darwin-release/lib/libz.a

Is there any way to change this behavior ?

For now, my workaround is to change vcpkg's APPEND to PREPEND.

vcpkg-bug

All 10 comments

Any new about this ? For now, changing APPEND to PREPEND fix pretty much the issues I had, making CMake use the vcpkg libraries before tryiing systems one.

@Nemirtingas There are two scenarios here:

  1. If you use the port that depends on zlib in vcpkg, you must use zlib in vcpkg because of its dependency.
  2. If not, you can remove zlib in vcpkg by command ./vcpkg remove zlib, then use find_package to find zlib on your own machine.

The thing is that my project looks for zlib, I build zlib with vcpkg (because curl needs it), but when building curl, it gets the system's zlib, not the one built by vcpkg

So you should execute the following steps:

  1. Completely remove zlib using command ./vcpkg remove zlib --recurse
  2. Remove folder _VCPKG_ROOT/buildtrees/curl/src_
  3. Use ./vcpkg install curl --editable and terminate the build process
  4. Remove the dependency of zlib in _VCPKG_ROOT/ports/curl/CONTROL_
  5. Specify the location of find zlib in the curl source _VCPKG_ROOT/buildtrees/curl/src/767f0f2a9e-91d24adee1/CMakeLists.txt_ line 632:
    find_package(ZLIB QUIET)
  6. Reinstall curl using command ./vcpkg install curl --editable

Doing so, I must again set a special case in my own project that also use zlib, and protobuf that has a feature to use zlib. In fact doing so I must modify every port that uses zlib to find the vcpkg one ?

@Nemirtingas I believe that because you modified the code of zlib, so you must use zlib on your machine.
In fact, you can apply the modification to the zlib of vcpkg to solve this problem once and for all without needing to modify curl.

I did not modify zlib.
I just used vcpkg install curl protobuf[zlib]
Doing so, zlib is build and installed by vcpkg, but all ports that use it show the line:
Found ZLIB: /usr/lib/libz.tbd (found version "1.2.11")
When changing the APPEND to PREDEND in vcpkg, I got
Found ZLIB: /vcpkg/x86-darwin-release/lib/libz.a

Oh, I know what you mean.
Yes, I think you are right, I will discuss with my colleagues.

Oh, I know what you mean.
Yes, I think you are right, I will discuss with my colleagues.

Ok thanks. I use my fork for now, so it doesn't really impact my builds. Thankfully vcpkg is editable ;)

oh, this definitely seems like an issue. @JackBoosY could you open a PR to fix this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pakdel picture pakdel  路  3Comments

ThinkalVB picture ThinkalVB  路  3Comments

jasjuang picture jasjuang  路  3Comments

angelmixu picture angelmixu  路  3Comments

grandprixgp picture grandprixgp  路  3Comments