Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors LNK2001 on linking with libversion on Windows [bug] #26

Open
AndreyMZ opened this issue Mar 6, 2021 · 0 comments
Open

Errors LNK2001 on linking with libversion on Windows [bug] #26

AndreyMZ opened this issue Mar 6, 2021 · 0 comments

Comments

@AndreyMZ
Copy link

AndreyMZ commented Mar 6, 2021

Problem description

The C library libversion is installed as the following:

  1. 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.
  2. 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 repology/py-libversion#8 (Build errors LNK2001 on Windows).

Steps to reproduce

  1. Build and install the C library libversion on 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"
    
  2. 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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant