Errors LNK2001 on linking with libversion on Windows [bug]
Problem description
The C library libversion is installed as the following:
C:\Program Files\libversion\lib\libversion.lib- the import library for load-time dynamic linking of the DLL. However, the DLL itself is not installed to the system.C:\Program Files\libversion\lib\version.lib- the static library.
The pkg-config file C:\Program Files\libversion\lib\pkgconfig\libversion.pc points to the second one (the static library version.lib). But the pkg-config does not contains the compiler option to define the macro LIBVERSION_STATIC_DEFINE which is required for linking with the static library.
This causes, in particular, the bug https://github.com/repology/py-libversion/issues/8 (Build errors LNK2001 on Windows).
Steps to reproduce
-
Build and install the C library
libversionon Windows:set LIBVERSION_REF=3.0.1 choco install -y git cmake visualstudio2017buildtools pkgconfiglite git clone https://github.com/repology/libversion.git --branch="%LIBVERSION_REF%" cd libversion cmake . -G "Visual Studio 15 2017 Win64" cmake --build . --config Release cmake --install . setx PKG_CONFIG_PATH "C:/Program Files/libversion/lib/pkgconfig" -
Check that it is discoverable by
pkg-config:pkg-config --libs --cflags libversion
Actual result
C:\libversion>pkg-config --libs --cflags libversion
-IC:/Program\ Files/libversion/include -LC:/Program\ Files/libversion/lib -lversion
Expected result
C:\libversion>pkg-config --libs --cflags libversion
-DLIBVERSION_STATIC_DEFINE -IC:/Program\ Files/libversion/include -LC:/Program\ Files/libversion/lib -lversion
or
C:\libversion>pkg-config --libs --cflags libversion
-IC:/Program\ Files/libversion/include -LC:/Program\ Files/libversion/lib -llibversion
Possible solution 1
Add the definition on the macro LIBVERSION_STATIC_DEFINE to the pkg-config file:
Libs: -L${libdir} -lversion
Cflags: -I${includedir} -DLIBVERSION_STATIC_DEFINE
Possible solution 2
Properly install the DLL and make the pkg-config file point to the import library (libversion.lib):
Libs: -L${libdir} -llibversion
Cflags: -I${includedir}