1

We have a problem where a library we build via vcpkg is incorrectly linked in some modules which do not use it, leading to incorrect functionality.

Because vcpkg links libraries automatically, we can't simply remove it from project->linker->additional libraries.

Is there a way I can, in a project's settings, override this to explicitly say "do NOT link to boost_thread-vc140-mt.lib?"

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

1 Answers1

2

I can think of two options: a) disable "autolink". Add these lines to your vcxproj oder to your Directory.Build.props file:

  <PropertyGroup>
    <VcpkgAutoLink>false</VcpkgAutoLink>
  </PropertyGroup>

This will disable the automatic link feature. The downside is that none of the libs will be linked automatically and you may have to explicitly add all the required libs to your project file. But if this is just one project, perhaps it is acceptable. (Note: I used VcpkgAutoLink in an older project, it may no longer work.)

b) Use manifests. This is a great idea and I really like the way it turns out. Add a file vcpkg.json to the root directory of your project(s). This file contains the exact list of libs you want to use with your project. And it is possible to have different vcpkg.json files in a solution - although you still have to make sure the versions are compatible of course.

With b) you can use the entire boost for most of the projects, but specify the exact boost libraries and versions for your lib. The file looks somewhat like this:

{
  "name": "mylib",
  "version": "0.9.0",
  "dependencies": [
    { "name": "boost-format" },
    { "name": "boost-preprocessor" },
    { "name": "boost-uuid" },
    { "name": "boost-lexical-cast" },
    { "name": "boost-bind" },
    {
      "name": "boost-serialization",
      "version>=": "1.40.0"
    },
    { "name": "boost-python" }
  ],
  "builtin-baseline": "6610ec0e042db81155f7ae72168f92f8a7741c2b",
  "overrides": [
    {
      "name": "python3",
      "version": "3.7.3-3"
    }
  ],
  "homepage": "https://izts09.izt.loc",
  "supports": "windows"
}

The "overrides" for example will let you downgrade (or upgrade) specific version requirements.

I am still experimenting with the "manifest" mode myself, but it's promising. BTW, you have to explicitly enable "manifest", AFAIK, by setting VCPKG_FEATURE_FLAGS=manifest for example.

Hajo Kirchhoff
  • 1,969
  • 8
  • 17