Skip to main content

libsystemd contains no symbols [Resolved]

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

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/, 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.

Question Credit: user907323
Question Reference
Asked May 13, 2019
Tags: systemd
Posted Under: Unix Linux
1 Answers

It’s a dynamic symbol:

$ nm -D /lib/x86_64-linux-gnu/ | 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.

credit: Stephen Kitt
Answered May 13, 2019
Your Answer