DaanDeMeyer / reproc

A cross-platform (C99/C++11) process library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

possible error in generated pkg-config file

franko opened this issue · comments

I have compiled the reproc library on windows using MSYS2 using the command:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DREPROC++=OFF -DBUILD_SHARED_LIBS=OFF ..

so I have disabled the build of the shared library to have only the static library.

Now the pkg-config --libs command on reproc will return "-lreproc" and not the ws2_32 library required on Windows. This is because the ws2_32 library is declared as private in the ".pc" file:

prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@

Name: @TARGET@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -l@TARGET@
Libs.private: @REPROC_THREAD_LIBRARY@ @REPROC_WINSOCK_LIBRARY@ @REPROC_RT_LIBRARY@

The problem is that I have installed only the static library and the ws2_32 is needed.

The pkg-config documentation states:

Libs.private: The link flags for private libraries required by this package but not exposed to applications. The same rule as Cflags applies here.

In my understanding, when the dynamic library is disabled and the static library is going to be used all the libraries required should be listed in "Libs:" in the .pc file because "they are exposed to applications".

From what I understand, it should be possible to use the same pkgconfig file for both static and dynamic versions of reproc. Shouldn't you be running pkg-config --libs --static when you're using reproc as a static library?

If a library is available only as a static library it means that an application that tries to link using pkg-config --libs will fail. So the application needs to know by some other means if the library is provided as a static or shared library and based on this information use a different pkg-config command, with or without the --static flag.

To me this is the wrong behavior. If the library is available as a static library the plain command pkg-config --libs should simply return the right flags to correctly link. Please note that this is normally how other library works when they are compiled and installed as a static library. This is also what Meson was doing for reproc out of the box with the configuration I proposed in the PR.

To me the --static flag is there only for the case when the library is provided both as a static or dynamic library. In this case the --static flag let you choose.