I\'m trying to compile an object code with a reference to one lib. This is the code of libexample.c:
#include \"libexample.h\"
#include
#include
The man timer_create
command explains you:
NAME
timer_create - create a POSIX per-process timer
SYNOPSIS
#include <signal.h>
#include <time.h>
int timer_create(clockid_t clockid, struct sigevent *sevp,
timer_t *timerid);
Link with -lrt.
So you should, as documentation says, link with -lrt
.
So use
gcc libexample.c -fPIC -shared -o libexample.so -lrt
to produce your libexample.so
.
As undur_gongor commented, you need to put the libraries in good order after all the rest (the usual order for gcc
arguments is source files, object files, libraries in dependency order) in gcc
or ld
commands (and that is documented in ld
documentation, and in gcc
ones). So -lrt
should go last.
And learn to read man pages.
If you are using cmake, make sure you include the libraries using target_link_libraries()
. For e.g., timer functions like timer_create()
you need "rt"
and for pthread
you need "pthread"
added using target_link_libraries()
.
Looks like you forgot to link in the library that defines timer_create and timer_settime -- you need to add -lrt
to your gcc
command.
(source: http://www.kernel.org/doc/man-pages/online/pages/man2/timer_create.2.html)
Add -lrt
to your link command. timer_create
and timer_settime
are not part of the C Standard library.
gcc -fPIC -shared libexample.c -lrt -o libexample.so
gcc -L. example.c -lexample -o example