Bug 10672 - Build fails trying to link to >=systemd-209 libraries
Summary: Build fails trying to link to >=systemd-209 libraries
Status: RESOLVED DUPLICATE of bug 11200
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Build (show other bugs)
Version: 4.1.8
Hardware: All Linux
: P5 major (vote)
Target Milestone: ---
Assignee: Alexander Bokovoy
QA Contact: Samba QA Contact
Depends on:
Reported: 2014-06-24 16:41 UTC by Tony Murray
Modified: 2016-02-12 00:08 UTC (History)
4 users (show)

See Also:

support systemd-209 (1.48 KB, patch)
2014-06-26 07:06 UTC, Alexander Bokovoy
no flags Details
config.log (198.81 KB, application/x-bzip)
2014-06-27 13:35 UTC, Tony Murray
no flags Details
support systemd-209 (1.19 KB, patch)
2014-06-27 16:32 UTC, Alexander Bokovoy
no flags Details
libsystemd.pc (526 bytes, application/octet-stream)
2014-07-07 15:28 UTC, Tony Murray
no flags Details
Fix systemd build (1.64 KB, patch)
2014-07-07 15:50 UTC, Tony Murray
no flags Details
Patch for git HEAD, supporting both new and old names (2.82 KB, patch)
2015-01-03 18:42 UTC, Michał Górny
no flags Details
The patch modified for v4-1-test branch (2.62 KB, patch)
2015-01-03 18:43 UTC, Michał Górny
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tony Murray 2014-06-24 16:41:32 UTC
Samba tries to directly link libsystemd-dameon.so, but that doesn't exist any more as of systemd-209.  The library that should be linked is libsystemd.so, see:


You probably need to detect the library name to support both versions.
Comment 1 Tony Murray 2014-06-24 16:43:39 UTC
Unable to attach log, here is the relevant output:

11:26:26 runner x86_64-pc-linux-gnu-gcc default/nsswitch/libwbclient/wbc_guid_1.o default/nsswitch/libwbclient/wbc_idmap_1.o default/nsswitch/libwbclient/wbclient_1.o default/nsswitch/libwbclient/wbc_pam_1.o default/nsswitch/libwbclient/wbc_pwd_1.o default/nsswitch/libwbclient/wbc_sid_1.o default/nsswitch/libwbclient/wbc_util_1.o -o /var/tmp/portage/net-fs/samba-4.1.8/work/samba-4.1.8/bin/default/nsswitch/libwbclient/libwbclient.so -march=native -O2 -pipe -Wl,-O1 -Wl,--as-needed -Wl,-O1 -Wl,--as-needed -fstack-protector -Wl,-no-undefined -Wl,--export-dynamic -lpthread -shared -Wl,--version-script=/var/tmp/portage/net-fs/samba-4.1.8/work/samba-4.1.8/bin/default/nsswitch/libwbclient/wbclient.vscript -Wl,-h,libwbclient.so.0 -Ldefault/lib/replace -Ldefault/nsswitch -L/usr/local/lib -Wl,-Bdynamic -lwinbind-client -lreplace -lattr -lnsl -ldl -lcrypt -lrt
default/lib/util/become_daemon_1.o: In function `become_daemon':
become_daemon.c:(.text+0x200): undefined reference to `sd_notifyf'
default/lib/util/become_daemon_1.o: In function `exit_daemon':
become_daemon.c:(.text+0x231): undefined reference to `sd_notifyf'
default/lib/util/become_daemon_1.o: In function `daemon_ready':
become_daemon.c:(.text+0x2b1): undefined reference to `sd_notifyf'
collect2: error: ld returned 1 exit status
Comment 2 Björn Jacke 2014-06-25 22:35:13 UTC
Alexander, any idea how to solve this nicely?
Comment 3 Alexander Bokovoy 2014-06-26 07:06:54 UTC
Created attachment 10053 [details]
support systemd-209

Attached is a patch for master. I haven't tried it as I don't have systemd-209 yet but this is what should help.
Comment 4 Tony Murray 2014-06-26 20:14:50 UTC
The patch does allow Samba to compile on my system.
Comment 5 Tony Murray 2014-06-27 00:55:47 UTC
I spoke too soon, it does not enable systemd:

Checking for libsystemd-daemon: yes 
Checking for header systemd/sd-daemon.h: yes 
Checking for library systemd-daemon: no 

Let me know if you want any more info.
Comment 6 Alexander Bokovoy 2014-06-27 05:28:33 UTC
Ok, I need to see build logs. Please attach a file named bin/config.log (you can compress it as it is ~15Mb large).
Comment 7 Björn Jacke 2014-06-27 11:45:28 UTC
also, can you post your pkg-config systemd*.pc files? On my distribution the systemd-*.pc pkg-config files have been patched to add the required new linker flags.
Comment 8 Tony Murray 2014-06-27 13:35:34 UTC
Created attachment 10058 [details]

FYI, I was trying to patch 4.1.8.  I had to modify it a bit to apply the patch here is that section to check to make sure I didn't mess it up.

    if Options.options.enable_systemd != False:
        r = conf.check_cfg(package='libsystemd-daemon', args='--cflags --libs',
                       msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
        if not r:
            conf.check_cfg(package='libsystemd', args='--cflags --libs',
                           msg='Checking for libsystemd', uselib_store="SYSTEMD-DAEMON")
        conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
        conf.CHECK_LIB('systemd-daemon', shlib=True)

        conf.DEFINE('HAVE_SYSTEMD', '1')
        conf.env['ENABLE_SYSTEMD'] = True
        conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
Comment 9 Alexander Bokovoy 2014-06-27 16:32:19 UTC
Created attachment 10059 [details]
support systemd-209

Ok, looking at your config.log, I can see that the way systemd team did transition is by keeping the same pkg-config package name (libsystemd-daemon) but providing a different library underneath. This is a sensible approach.

So, can you try this patch instead? It only adds a check for additional library, libsystemd. This library does not exist in case of systemd < 2.0.9 but for that case we have libsystemd-daemon. Both of them would be covered by the same pkg-config package, called libsystemd-daemon.
Comment 10 Tony Murray 2014-07-07 15:28:24 UTC
Created attachment 10074 [details]
Comment 11 Tony Murray 2014-07-07 15:50:36 UTC
Created attachment 10075 [details]
Fix systemd build

This seems to fix the build, probably not not the correct fix, but hopefully it helps point you guys in the right direction.
Comment 12 Mike Gilbert 2014-10-17 17:05:45 UTC
(In reply to Alexander Bokovoy from comment #9)
> Ok, looking at your config.log, I can see that the way systemd team did transition is by keeping the same pkg-config package name (libsystemd-daemon) but providing a different library underneath. This is a sensible approach.

That's not accurate. The systemd build system does NOT install libsystemd-deamon.pc by default. On Gentoo Linux, we install it as a hack to avoid breaking lots of packages that look for it.

To be compatible with systemd as shipped by default, you would need to check for libsystemd.pc and libsystemd-daemon.pc as a fall back.
Comment 13 Michał Górny 2015-01-03 18:40:50 UTC
The currently attached patches can't work properly because of how samba build system works.

Long story short:

 219         conf.check_cfg(package='libsystemd-daemon', args='--cflags --libs',
 220                        msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")

This gets --libs from pkg-config and puts them in LIBS_SYSTEMD-DAEMON.

 221         conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
 222         conf.CHECK_LIB('systemd-daemon', shlib=True)

And this checks for '-lsystemd-daemon' (ignoring --libs above). If it is found, it is written to LIBS_SYSTEMD-DAEMON, therefore overwriting the result of pkg-config. If it is not, 'systemd-daemon' becomes EMPTY target, effectively making the pkg-config result irrelevant.
Comment 14 Michał Górny 2015-01-03 18:42:55 UTC
Created attachment 10571 [details]
Patch for git HEAD, supporting both new and old names

This patch specifically:

1. checks both for libsystemd and libsystemd-daemon via pkg-config,

2. checks both for -lsystemd and -lsystemd-daemon using lib checks,

3. enables systemd support if either of the two is found, and names both as deps of the util library.

So on systems having libsystemd, the first check will succeed and the other target will be EMPTY. On systems having libsystemd-daemon, the second check will succeed and 'systemd' will be EMPTY.
Comment 15 Michał Górny 2015-01-03 18:43:41 UTC
Created attachment 10572 [details]
The patch modified for v4-1-test branch
Comment 16 Tony Murray 2015-01-05 14:47:02 UTC
Michał's patch is confirmed working for me.  I also notice that Gentoo picked up this patch.
Comment 17 Andrew Bartlett 2016-02-11 21:42:58 UTC
(In reply to Michał Górny from comment #15)
Can you please provide a tested patch against Samba git master?

That way we can get this into 4.4.

Comment 18 Andrew Bartlett 2016-02-12 00:08:44 UTC
Looks like this is fixed as of 5ee27b4ead57c15db7168d80f6fdf821663c44fc at Wed Apr  8 15:06:26 CEST 2015

*** This bug has been marked as a duplicate of bug 11200 ***