I'm trying to compile the following foo.c:

#include <systemd/sd-journal.h>
int main(int argc, char *argv[]) {
        sd_journal_print(LOG_NOTICE, "Hello World");
        return 0;


gcc `pkg-config --cflags --libs libsystemd` foo.c

Getting an ld error: undefined reference to 'sd_journal_print_with_location'

When I run nm /lib/x86_64-linux-gnu/libsystemd.so.0.14.0, which I believe is the lib that should contain the definition of this and other sd_ functions, I get: no symbols. (same result with other symbol listing utilities).

A shared lib with no symbols?

I'm on Ubuntu 16.04, installed libsystemd-dev with apt. Some sources refer to libsystemd-journal-dev, but I don't believe it exists for my distro.

All I'm trying to do is figure out how to use systemd's journal for system-wide logging. I understand I can probably use syslog, and it will use systemd behind the scenes, but would rather understand what's going on here.


1 Answer 1


It’s a dynamic symbol:

$ nm -D /lib/x86_64-linux-gnu/libsystemd.so.0.25.0 | grep sd_journal_print_with_location
0000000000026ec0 T sd_journal_print_with_location

To build your program, you need to specify the library after its users:

gcc $(pkg-config --cflags libsystemd) foo.c $(pkg-config --libs libsystemd)

The package you need is libsystemd-dev.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .