Bug 19541 - PKG_CHECK_MODULES doesn't allow a variant for static linking
Summary: PKG_CHECK_MODULES doesn't allow a variant for static linking
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Dan Nicholson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-13 11:00 UTC by Peter Clifton
Modified: 2013-05-19 02:40 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
m4 macro to check for static or dynamic dependencies (2.16 KB, text/plain)
2013-03-07 10:45 UTC, Nikos Mavrogiannopoulos
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Clifton 2009-01-13 11:00:51 UTC
When linking to a library statically, I need to pass --static to pkg-config in order for it to provide the correct list of libraries to link with.

Unfortunately, PKG_CHECK_MODULES doesn't allow this as an option, so I can't see a nice auto-foo way to choose to link against a particular library statically.
Comment 1 Tollef Fog Heen 2009-12-06 12:19:31 UTC
Fixed in git commit 6a2c307ed21dd90e23fe576e797d469b2d2eedaa
Comment 2 Tollef Fog Heen 2009-12-06 12:52:35 UTC
Sorry, that was the wrong bug being closed.

You can work around this by overriding PKG_CONFIG for those libraries you need to do statically.

I'll leave this bug open for now.
Comment 3 Dan Nicholson 2012-12-09 05:32:47 UTC
I've thought about this a few times and don't know if there's a good solution to it. It depends what kind of behavior we're looking for. I can think of two scenarios where someone wants --static behavior to be included in PKG_CHECK_MODULES.

1. The user wants to link the program/library statically.

2. The developer wants to link the program/library statically.

In both situations, just setting PKG_CONFIG='pkg-config --static' will provide the desired results. For the user, it's not fine-grained at all in that they would have to pass this to configure either through the environment or on the command line. That means all PKG_* checks will result in --static output.

For the developer, they could easily override with PKG_CONFIG="$PKG_CONFIG --static" in the specific scenarios they want --static output. It's not that pretty, but the capability is definitely there.

What I don't think would be very clean is to duplicate all the PKG_* autoconf macros with a _STATIC variant. That would require all projects to have to pick one or support both variants of the macro.

Another possibility is to add a STATIC argument to the macros. This would basically happen silently for everyone since m4 has no issues with unused arguments. However, that would still require projects to explicitly pass something in for the argument, which undermines the idea that it could happen transparently.

An idea I had was to add a PKG_ENABLE_STATIC/PKG_DISABLE_STATIC similar to the old libtool macros. This would just add or not add --static to PKG_CONFIG. It could provide a configure option like --enable-pkg-config-static or something like that. The macro could be added by the developer around the spots they wanted to have static linking. By default PKG_DISABLE_STATIC would be set by PKG_PROG_PKG_CONFIG to maintain the current behavior. It seems like overkill, though.
Comment 4 Nikos Mavrogiannopoulos 2013-03-07 10:45:44 UTC
Created attachment 76106 [details]
m4 macro to check for static or dynamic dependencies
Comment 5 Nikos Mavrogiannopoulos 2013-03-07 10:47:16 UTC
Comment on attachment 76106 [details]
m4 macro to check for static or dynamic dependencies

I believe having a "STATIC" argument is required when some libraries may be statically linked while others not. This macro allows one specify the "STATIC" type.
Comment 6 Dan Nicholson 2013-05-18 03:11:34 UTC
Sorry I missed this before. I definitely understand what you're going for there, but how is it better than this (which doesn't entirely duplicate PKG_CHECK_MODULES)?

PKG_PROG_PKG_CONFIG
PKG_CONFIG="$PKG_CONFIG --static"
PKG_CHECK_MODULES([FOO], [bar])

Actually, I guess PKG_CHECK_MODULES_STATIC could easily be implemented as:

AC_DEFUN([PKG_CHECK_MODULES_STATIC],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
_save_PKG_CONFIG=$PKG_CONFIG
PKG_CONFIG="$PKG_CONFIG --static"
PKG_CHECK_MODULES([$1], [$2], [$3], [$4], [$5])
PKG_CONFIG=$_save_PKG_CONFIG[]dnl
])

While either your patch or this suggestion offer the developer a way to specify static linking, it offers no control to the user besides a giant hammer PKG_CONFIG='pkg-config --static'. Again, I'm not sure what people are looking for here.
Comment 7 Dan Nicholson 2013-05-19 02:40:34 UTC
(In reply to comment #6)
> 
> Actually, I guess PKG_CHECK_MODULES_STATIC could easily be implemented as:
> 
> AC_DEFUN([PKG_CHECK_MODULES_STATIC],
> [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
> _save_PKG_CONFIG=$PKG_CONFIG
> PKG_CONFIG="$PKG_CONFIG --static"
> PKG_CHECK_MODULES([$1], [$2], [$3], [$4], [$5])
> PKG_CONFIG=$_save_PKG_CONFIG[]dnl
> ])

I added a PKG_CHECK_MODULES_STATIC as above in commit 0efb668. It provides developers a simple means to get --static flags for a set of modules. However, it doesn't provide the user a fine-grained way of saying which module sets would be static or not. For that, the user just needs to run configure with PKG_CONFIG="pkg-config --static". I think that's about the best we can do.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.