GNOME Bugzilla – Bug 665298
Add 'Requires.private: libpcre' to glib-2.0.pc
Last modified: 2011-12-02 20:10:34 UTC
Static linking glib fails when GRegex is used in the program. Test case: #include <glib.h> int main (int argc, char *argv[]) { GRegex *regex; GError *error = NULL; regex = g_regex_new (".", (GRegexCompileFlags)0, (GRegexMatchFlags)0, &error); g_assert_no_error (error); g_regex_unref (regex); return 0; } Output: :~$ g++ -c `pkg-config --static --cflags glib-2.0` glib-test.c -o glib-test.o && g++ -static glib-test.o `pkg-config --static --libs glib-2.0` -o glib-test /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.o): In function `g_get_any_init_do': (.text+0xe35): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.o): In function `g_get_any_init_do': (.text+0xe29): warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.o): In function `g_get_any_init_do': (.text+0xe3f): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.o): In function `g_get_any_init_do': (.text+0xb93): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.o): In function `g_get_any_init_do': (.text+0xbc8): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `get_matched_substring_number': (.text+0x2d3): undefined reference to `pcre_get_stringtable_entries' /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `get_matched_substring_number': (.text+0x351): undefined reference to `pcre_get_stringnumber' /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `g_match_info_next': (.text+0x11b4): undefined reference to `pcre_exec' /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `match_info_new': (.text+0x141b): undefined reference to `pcre_fullinfo' /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `g_regex_unref': (.text+0x1484): undefined reference to `pcre_free' /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/libglib-2.0.a(gregex.o): In function `g_regex_unref': (.text+0x1493): undefined reference to `pcre_free' ... etc. for every symbol
Created attachment 202529 [details] [review] Link to libpcre when static linking Add libpcre to Requires.private in glib-2.0.pc, so that it is passed to the linker correctly when GLib is being statically linked.
Comment on attachment 202529 [details] [review] Link to libpcre when static linking It should only include that if --with-pcre=system
Created attachment 202541 [details] [review] Link to libpcre correctly when static linking
Turns out configure was already generating the right variable, it just wasn't getting substituted in the .pc
Still need to address Comment #2 .
Oh, I guess you were relying on it expanding to the empty string if --with-pcre=internal. But since we don't call AC_SUBST in that case, doesn't it blow up? Let me actually try...
All cases work, although I agree that it seems like it should blow up. I think we're confusing AC_SUBST with AM_CONDITIONAL (which you can't conditionally call). The autoconf manual doesn't warn against behaving like this: http://www.gnu.org/s/hello/manual/autoconf/Setting-Output-Variables.html
I'd be suspicious just like Colin...but looking at configure.ac, we have prior art for this, e.g. AC_MSG_CHECKING([whether to disable memory pools]) if test "x$disable_mem_pools" = "xno"; then AC_MSG_RESULT([no]) else AC_DEFINE(DISABLE_MEM_POOLS, [1], [Whether to disable memory pools]) AC_SUBST(DISABLE_MEM_POOLS) AC_MSG_RESULT([yes]) fi I see: config.h:/* #undef DISABLE_MEM_POOLS */ config.status:S["DISABLE_MEM_POOLS"]="" in my build, so the AC_DEFINE was not taken, but the AC_SUBST still had the desired effect.
Attachment 202541 [details] pushed as 15437a7 - Link to libpcre correctly when static linking