vcpkg icon indicating copy to clipboard operation
vcpkg copied to clipboard

[ThorVG] Static linking on Windows fails with LNK2019

Open tschnz opened this issue 6 months ago • 1 comments

Operating system

Windows 11 Pro (10.0.26100 Build 26100)

Compiler

MSVC 19.44.35208 64bit

Steps to reproduce the behavior

- Add `thorvg` and `pkgconf` to vcpkg.json
- `vcpkg install`
- Copy files for minimal example (attached)
- Configure with `cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=...`
- Build and see LNK2019

Failure logs

FAILED: ThorVG_Test.exe C:\Windows\system32\cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --msvc-ver=1944 --intdir=CMakeFiles\ThorVG_Test.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~2\2022\PROFES~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\ThorVG_Test.dir\main.cpp.obj /out:ThorVG_Test.exe /implib:ThorVG_Test.lib /pdb:ThorVG_Test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console vcpkg_installed\x64-windows-static\debug\lib\thorvg.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && C:\Windows\system32\cmd.exe /C "cd /D C:\develop\jens\GitHub\ThorVG_test\sources\build && "C:\Program Files\PowerShell\7\pwsh.exe" -noprofile -executionpolicy Bypass -file C:/develop/jens/GitHub/ThorVG_test/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/develop/jens/GitHub/ThorVG_test/sources/build/ThorVG_Test.exe -installedDir C:/develop/jens/GitHub/ThorVG_test/sources/build/vcpkg_installed/x64-windows-static/debug/bin -OutVariable out"" LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\PROFES~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\ThorVG_Test.dir\main.cpp.obj /out:ThorVG_Test.exe /implib:ThorVG_Test.lib /pdb:ThorVG_Test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console vcpkg_installed\x64-windows-static\debug\lib\thorvg.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\ThorVG_Test.dir/intermediate.manifest CMakeFiles\ThorVG_Test.dir/manifest.res" failed (exit code 1120) with the following output: main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static enum tvg::Result __cdecl tvg::Initializer::init(enum tvg::CanvasEngine,unsigned int)" (_imp?init@Initializer@tvg@@SA?AW4Result@2@W4CanvasEngine@2@I@Z) referenced in function main ThorVG_Test.exe : fatal error LNK1120: 1 unresolved externals ninja: build stopped: subcommand failed.

Additional context

I'm just trying to build a minimal example on Win64 with static linking:

#include <thorvg.h>

int main() {
  tvg::Initializer::init(tvg::CanvasEngine::Sw, 0);
  return 0;
}

CMakeLists.txt vcpkg.json

tschnz avatar Jun 11 '25 15:06 tschnz

Sorry, to reproduce you need to explicitly configure with static triplet

cmake -B build -G Ninja -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=...\vcpkg\scripts\buildsystems\vcpkg.cmake

tschnz avatar Jun 12 '25 08:06 tschnz

Looks like TVG_STATIC wasn't set? If I put #define TVG_STATIC 1 before the ThorVG include it compiles and links

tschnz avatar Jun 16 '25 09:06 tschnz