After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 654078 - Fail to static linking with Glib library
Fail to static linking with Glib library
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.29.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-07-06 11:46 UTC by Slava Zanko
Modified: 2011-07-24 16:22 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Slava Zanko 2011-07-06 11:46:06 UTC
Operating System:

LSB Version:    :core-4.0-amd64:core-4.0-noarch
Distributor ID: Fedora
Description:    Fedora release 15 (Lovelock)
Release:        15
Codename:       Lovelock


Description of problem:

Unable to linking with libglib-2.0.a

Version-Release number of selected component:

glib-2.29.10


How reproducible:
try linking libglib-2.0.a with any program


Steps to Reproduce:

1. Download & compile. Configure parameters:
./configure --enable-static

2. create test file:
$ cat test_glib.static.c 
#include <glib.h>

int main(void)
{
    char *test;
    test = g_new0(char,1);
    g_free(test);

    return 0;
}

3. Try to compile:
$ gcc $(pkg-config --cflags glib-2.0) test_glib.static.c libglib-2.0.a


Actual results:

libglib-2.0.a(gslice.o):(.note.stapsdt+0x24): undefined reference to `glib_slice__alloc_semaphore'
libglib-2.0.a(gslice.o):(.note.stapsdt+0x70): undefined reference to `glib_slice__free_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x24): undefined reference to `glib_mem__alloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x7c): undefined reference to `glib_mem__alloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0xd0): undefined reference to `glib_mem__alloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x128): undefined reference to `glib_mem__alloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x17c): undefined reference to `glib_mem__realloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x1d8): undefined reference to `glib_mem__realloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x230): undefined reference to `glib_mem__free_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x274): undefined reference to `glib_mem__alloc_semaphore'
libglib-2.0.a(gmem.o):(.note.stapsdt+0x2cc): undefined reference to `glib_mem__realloc_semaphore'
libglib-2.0.a(gdataset.o):(.note.stapsdt+0x24): undefined reference to `glib_quark__new_semaphore'
libglib-2.0.a(gdataset.o):(.note.stapsdt+0x70): undefined reference to `glib_quark__new_semaphore'
libglib-2.0.a(gdataset.o):(.note.stapsdt+0xbc): undefined reference to `glib_quark__new_semaphore'
libglib-2.0.a(gdataset.o):(.note.stapsdt+0x108): undefined reference to `glib_quark__new_semaphore'
libglib-2.0.a(gmain.o): In function `g_get_monotonic_time':
(.text+0x35e2): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status


Expected results:
should be a.out file here.
Comment 1 Colin Walters 2011-07-22 16:45:24 UTC
You should be using:

pkg-config --static --libs

That reveals a glib bug, which this commit fixes:

commit b79eae5c197aeec8d57f39c0f7bf5d5114068bea
Author: Colin Walters <walters@verbum.org>
Date:   Fri Jul 22 12:41:41 2011 -0400

    glib-2.0.pc: Add -lrt to private libraries to assist static linking
Comment 2 Colin Walters 2011-07-22 16:46:53 UTC
(Also, I should note that statically linking glib is a bad idea.  If your app needs to run on an old version of a GNOME-based OS, shipping a newer libglib.so in a private directory and setting an RPATH on your executable is a better idea).
Comment 3 Slava Zanko 2011-07-24 16:07:18 UTC
Sorry, but issue still alive :)

$ git branch
* master
$ git pull
Already up-to-date.
$ git descrbe
2.29.14-20-g4cb33b1

I have configured glib as:
./configure --enable-static --prefix=/home/slavaz/work/mc/related-srcs/111/

After installing Glib i ran my test (see description of this bug at top of page):
$ export PKG_CONFIG_PATH=/home/slavaz/work/mc/related-srcs/111/lib/pkgconfig
$ gcc -static $(pkg-config --cflags glib-2.0) test_glib.static.c $(pkg-config --static --libs glib-2.0)

And I see errors:
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gutils.o): In function `g_get_any_init_do':
/home/slavaz/work/mc/related-srcs/glib/glib/gutils.c:1858: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/slavaz/work/mc/related-srcs/glib/glib/gutils.c:1857: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/slavaz/work/mc/related-srcs/glib/glib/gutils.c:1859: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/slavaz/work/mc/related-srcs/glib/glib/gutils.c:1801: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/slavaz/work/mc/related-srcs/glib/glib/gutils.c:1807: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gslice.o):(.note.stapsdt+0x24): undefined reference to `glib_slice__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gslice.o):(.note.stapsdt+0x70): undefined reference to `glib_slice__free_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x24): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x7c): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0xd0): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x128): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x17c): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x1d8): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x230): undefined reference to `glib_mem__free_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x274): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x2cc): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x24): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x70): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0xbc): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x108): undefined reference to `glib_quark__new_semaphore'
collect2: ld returned 1 exit status

Probably, some thread-related stuff with semaphores didn't included to static lib...

> Also, I should note that statically linking glib is a bad idea.
On embedded systems statically linking is very usefull idea (especially if Glib used only by one application, such as Midnight Commander).
Comment 4 Slava Zanko 2011-07-24 16:22:01 UTC
In addition: I ran linking without -static flag to gcc and I specify full path to static Glib library:

$ export PKG_CONFIG_PATH=/home/slavaz/work/mc/related-srcs/111/lib/pkgconfig
$ gcc $(pkg-config --cflags glib-2.0) test_glib.static.c /home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a -lrt

/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gslice.o):(.note.stapsdt+0x24): undefined reference to `glib_slice__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gslice.o):(.note.stapsdt+0x70): undefined reference to `glib_slice__free_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x24): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x7c): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0xd0): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x128): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x17c): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x1d8): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x230): undefined reference to `glib_mem__free_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x274): undefined reference to `glib_mem__alloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gmem.o):(.note.stapsdt+0x2cc): undefined reference to `glib_mem__realloc_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x24): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x70): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0xbc): undefined reference to `glib_quark__new_semaphore'
/home/slavaz/work/mc/related-srcs/111/lib/libglib-2.0.a(gdataset.o):(.note.stapsdt+0x108): undefined reference to `glib_quark__new_semaphore'
collect2: ld returned 1 exit status

As you see, librt-related warning is gone, but 'glib_*_semaphore' error still present.