Search code examples
c++static-librarieslinker-errorsliblibsndfile

Errors when statically linking libsndfile with vcpkg and running sf_open


So here's a bit of example code:

#include<sndfile.h>

int main() { SNDFILE* sndfile; SF_INFO sfinfo; sndfile = sf_open("", SFM_READ, &sfinfo); std::cout << "Hello, World!"; }

So basically I'm statically linking it from vcpkg, and I followed all the steps like using :x64-windows-static at the end, changing the visual studio settings and configuration file, and more, but for some reason I get these errors specifically when I compile statically and when using sf_open.

Errors:

3 unresolved externals unresolved external symbol __imp_PathCombineW referenced in function INT123_compat_catpath unresolved external symbol __imp_PathIsRelativeW referenced in function wpath_need_elongation unresolved external symbol __imp_PathIsUNCW referenced in function wlongpath

Note: Yes I do realize that libsndfile is licensed under LGPL, so I plan to include the object files since that apparently allows me to statically link it.


Solution

  • These are functions from the windows api. Just Google them and the msdn help page will tell you which windows library you need to link.

    For example PathCombineW has this help page: https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathcombinew in the Requirements section it tells you that you need to link to Shlwapi.lib