使用随vcpkg安装的库时出现LNK2019错误

时间:2020-10-20 08:55:02

标签: c++ linker visual-studio-2019 vcpkg

我已经使用正确的三元组和vcpkg安装了库:

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

然后我执行了以下命令:

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"

但是在我的带有x64项目的Visual Studio 2019项目中,只有标头已成功集成:

#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
}

尝试编译时,我得到:

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 ==========

顺便说一句,我已经查找了噪声库的.lib文件的名称,并试图将它们添加到“链接器”>“输入”属性中,但仍然无法正常工作。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

要启用自动链接,请选择当前项目并转到属性。 (按Enter键)请确保您编辑正确的配置。然后转到配置属性-> vcpkg,并确保启用了自动链接。

答案 1 :(得分:0)

它已由开发人员在GitHub上修复:https://github.com/microsoft/vcpkg/issues/14127