How to compile a system program using libsystemd-dev?

Asked by Robert M. Koretsky

I'm trying to compile a simple system program on Ubuntu 16.04 that uses the systemd native API calls for Journal logging.

I installed the libsystemd-dev package using the Software Manager, but don't know how to connect to the libraries it provides. For example, when I use the compiler directives `pkg-config --cflags --libs libsystemd-journal` that the blog "systemd for developers III" gives me, I get the following error:

Package libsystemd-journal was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsystemd-journal.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libsystemd-journal' found

I am compiling the provided Journal logging example found in the blog "systemd for developers III", as follows:

#include <systemd/sd-journal.h>

int main(int argc, char *argv[]) {
        sd_journal_print(LOG_NOTICE, "Hello World");
        return 0;
}

Any help would be greatly appreciated!

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Colin Watson
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

If I search at http://packages.ubuntu.com/search?suite=all&searchon=names&keywords=libsystemd-journal it seems that libsystemd-journal0 and libsystemd-journal-dev exist only up to Ubuntu 14.04
(I do not have any knowledge on the background of the removal.)

Which Ubuntu release was the blogger using when he wrote his entry?

Revision history for this message
Robert M. Koretsky (bobk48) said :
#2

Manfred:
Lennart Poettering gave these instructions in his blog "systemd for
developers III" from 2012, so whatever Ubuntu was active then. I don't
think he made this blog entry with Ubuntu specifically in mind, so however
the libraries and their locations exist in Ubuntu 16.04 is of interest to
me. I mean the Software Manager does provide systemd-dev, you would think
that once it was installed, compiling programs with gcc would hook to those
libraries, ce nez pas?. Not as easy a cookie to crumble as it appears.
That's so I can compile even the simplest program he shows, using Journal
API calls shown in the example.
Thanks for your reply!
Sincerely,
Robert M. Koretsky

On Tue, Jul 19, 2016 at 6:27 AM, Manfred Hampl <
<email address hidden>> wrote:

> Your question #297808 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/297808
>
> Status: Open => Answered
>
> Manfred Hampl proposed the following answer:
> If I search at
> http://packages.ubuntu.com/search?suite=all&searchon=names&keywords=libsystemd-journal
> it seems that libsystemd-journal0 and libsystemd-journal-dev exist only up
> to Ubuntu 14.04
> (I do not have any knowledge on the background of the removal.)
>
> Which Ubuntu release was the blogger using when he wrote his entry?
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/ubuntu/+question/297808/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+question/297808
>
> You received this question notification because you asked the question.
>

Revision history for this message
Best Colin Watson (cjwatson) said :
#3

libsystemd-journal was merged into libsystemd in systemd 209 (see its NEWS file). As a result, you should now just use `pkg-config --cflags --libs libsystemd` rather than `pkg-config --cflags --libs libsystemd-journal`.

Revision history for this message
Robert M. Koretsky (bobk48) said :
#4

Colin:
That was exactly the solution, my friend!
Thanks so much for the considerate, accurate, and helpful answer.
Sincerely,
Robert M. Koretsky

On Tue, Jul 19, 2016 at 8:08 AM, Colin Watson <
<email address hidden>> wrote:

> Your question #297808 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/297808
>
> Status: Open => Answered
>
> Colin Watson proposed the following answer:
> libsystemd-journal was merged into libsystemd in systemd 209 (see its
> NEWS file). As a result, you should now just use `pkg-config --cflags
> --libs libsystemd` rather than `pkg-config --cflags --libs libsystemd-
> journal`.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/ubuntu/+question/297808/+confirm?answer_id=2
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+question/297808
>
> You received this question notification because you asked the question.
>

Revision history for this message
Robert M. Koretsky (bobk48) said :
#5

That did it exactly! Thanks!
Not sure if installing libsystemd-dev from the Software Manager had anything to do with it, but it couldn't have hurt. I don't know where libsystemd-dev installed anything anyway, or if I'll ever have to rely on it.

Revision history for this message
Colin Watson (cjwatson) said :
#6

It is indeed necessary to have libsystemd-dev installed in order to build anything linked against libsystemd.

Revision history for this message
Robert M. Koretsky (bobk48) said :
#7

Colin:
Thanks, I was just about to test that on another machine. You saved me a
lot of time and effort, as well as expediting the rather newbie systems
programs I am playing with.
Robert M. Koretsky

On Tue, Jul 19, 2016 at 8:57 AM, Colin Watson <
<email address hidden>> wrote:

> Your question #297808 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/297808
>
> Colin Watson posted a new comment:
> It is indeed necessary to have libsystemd-dev installed in order to
> build anything linked against libsystemd.
>
> --
> You received this question notification because you asked the question.
>