[odb-users] Got "locally defined symbol imported" with pkg-config and dynamic linking

Boris Kolpackov boris at codesynthesis.com
Thu May 26 08:45:29 EDT 2022

acsvln <acsvln at disroot.org> writes:

> i looked at my install folder and found there .lib files and dll.lib

Right, .lib are static libraries and .dll.lib are DLL import libraries.

> Manually checked what pkg-config returns:
> C:\Windows\System32>pkg-config libodb-pgsql.static --cflags --libs --msvc-syntax
> -DLIBODB_PGSQL_BUILD2 -DLIBODB_PGSQL_STATIC -IC:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\include  /libpath:C:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\lib odb-pgsql.lib odb.lib
> C:\Windows\System32>pkg-config libodb-pgsql.shared --cflags --libs --msvc-syntax
> -DLIBODB_PGSQL_BUILD2 -DLIBODB_PGSQL_SHARED -IC:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\include  /libpath:C:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\lib odb-pgsql.lib odb.lib
> After that, i manually fixed pkg-config files, to link with .dll.lib files
> e.x:
> From:
> [...]
> Libs: -LC:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\lib -lcrypto
> To:
> [...]
> Libs: -LC:\\Temp\\dependencies\\install\\x64\\build2\\libodb-pgsql\\release\\lib -lcrypto.dll
> And now it working!
> Wanna to ask, is that bug and what i must do in my situation?

Good question (and nice investigation). I think my answer is that
the translation of the UNIX-centric pkg-config semantics to Windows
is under-specified and, as a result, different build systems translate
the UNIX model to Windows in their own ways. Especially the part on
how the same .pc file maps to static/shared libraries.

In case of build2, we always put a UNIX-style -l<name> into the .pc
file and leave it to the build system to map it to the concrete static
or shared library, or both, depending on what's available on the file
system. Also, on Windows, we've decided to follow the MinGW lead and
name import libraries as .dll.lib so that they can co-exist in the
same directory, similar to UNIX. As a result, a build system that
doesn't follow the same mapping, will unfortunately have a difficult
time using build2-generated .pc files.

As for what to do, the only two options that I can think of are to
fixup the .pc files like you did (maybe with a help of a script) or
to not use the .pc files at all (i.e., install everything into a
single location and manually provide the necessary -I/-L options plus,
potentially, additional libraries to link). Well, I guess there is a
third options: switch from qmake to build2 ;-).

More information about the odb-users mailing list