LNK2019 error when using a library installed with vcpkg

3.6k views Asked by At

I have installed libraries with vcpkg using the correct triplet :

C:\Users\***>vcpkg list libnoise
libnoise:x64-windows              1.0.0       A general-purpose library that generates three-d...

Then I have executed the following command :

C:\Users\***>vcpkg integrate install
Applied user-wide integration for this vcpkg root.

All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.

CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/Windows/vcpkg/scripts/buildsystems/vcpkg.cmake"

But in my Visual Studio 2019 project, with an x64 project, only the headers have been successfully integrated :

#include <noise/noise.h> // The header is found as well as the definition of noise::module::Perlin

int main()
{
   noise::module::Perlin noise; // The implementation is not found
}

When trying to compile this, I get :

1>------ Build started: Project: Mayak, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin@module@noise@@QEAA@XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl noise::module::Perlin::Perlin(void)" (__imp_??0Perlin@module@noise@@QEAA@XZ)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin@module@noise@@UEAA@XZ) referenced in function main
1>NoiseVideoGenerator.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl noise::module::Perlin::~Perlin(void)" (__imp_??1Perlin@module@noise@@UEAA@XZ)
1>C:\Users\sylva\source\repos\Mayak\x64\Debug\Mayak.exe : fatal error LNK1120: 2 unresolved externals
1>Done building project "Mayak.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

On a side note, I have looked for the name of the .lib files of the noise library and tried to add them in the Linker > Input properties, it still doesn't work.

What did I do wrong ?

2

There are 2 answers

0
Xobtah On BEST ANSWER

It has been fixed by the developers, on GitHub : https://github.com/microsoft/vcpkg/issues/14127

4
Simon On

To enable AutoLink, select your current project and go to properties. (Alt-Enter) Make sure you edit the right configuration. Then go to Configuration Properties -> vcpkg and make sure AutoLink is enabled.