You are not logged in.

#1 2008-06-14 22:13:22

jacko
Member
Registered: 2007-11-23
Posts: 840

link librt explicitly with -lrt switches.

I believe I need to do what the title of this thread says (link librt explicitly with -lrt switches.)

I am not sure how to do this at all.

Here is my code snipplet, I was asked by a dev to recompile this code and see if it works, yet I can't for the life of me accomplish recompiling this with this new code snipplet.

if I don't add in #include <time.h> line I get a different error, SO I think its needed

#include "quakedef.h"

#ifdef WIN32
#include <io.h>
#include "conio.h"
#else
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#endif

#include <signal.h>

the part of code I patched, using clock_gettime() instead of gettimeofday()

struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC,  &ts);
        newtime = (double) ts.tv_sec + ts.tv_nsec / 1000000000.0;

the error I get is this during compile time.

#
gcc -o nexuiz-dedicated builddate.c sys_linux.o vid_null.o snd_null.o cd_null.o cd_shared.o cl_collision.o cl_demo.o cl_dyntexture.o cl_gecko.o cl_input.o cl_main.o cl_parse.o cl_particles.o cl_screen.o cl_video.o clvm_cmds.o cmd.o collision.o common.o console.o csprogs.o curves.o cvar.o dpvsimpledecode.o filematch.o fractalnoise.o fs.o gl_backend.o gl_draw.o gl_rmain.o gl_rsurf.o gl_textures.o host.o host_cmd.o image.o image_png.o jpeg.o keys.o lhnet.o libcurl.o mathlib.o matrixlib.o mdfour.o menu.o meshqueue.o model_alias.o model_brush.o model_shared.o model_sprite.o mvm_cmds.o netconn.o palette.o polygon.o portals.o protocol.o prvm_cmds.o prvm_edict.o prvm_exec.o r_explosion.o r_lerpanim.o r_lightning.o r_modules.o r_shadow.o r_sky.o r_sprites.o sbar.o sv_demo.o sv_main.o sv_move.o sv_phys.o sv_user.o svbsp.o svvm_cmds.o sys_shared.o vid_shared.o view.o wad.o world.o zone.o -O2 -fno-strict-aliasing -march=i686 -mtune=generic -O2 -pipe -lm -ldl
#
sys_linux.o: In function `Sys_DoubleTime':
#
sys_linux.c:(.text+0x1b5): undefined reference to `clock_gettime'
#
collect2: ld returned 1 exit status
#
make[3]: *** [nexuiz-dedicated] Error 1
#
make[3]: Leaving directory `/home/jasin/nexuiz/src/Nexuiz/darkplaces'
#
make[2]: *** [bin-release] Error 2
#
make[2]: Leaving directory `/home/jasin/nexuiz/src/Nexuiz/darkplaces'
#
make[1]: *** [sv-nexuiz] Error 2
#
make[1]: Leaving directory `/home/jasin/nexuiz/src/Nexuiz/darkplaces'
#
make: *** [nexuiz] Error 2
#
==> ERROR: Build Failed.

all the googling searching leads me to believe explicitly telling the GNU linker (ld) to use the -lrt switches is all i need for the fix. Can anyone tell me how I can do that. Or how else I may solve this little issue. I am not a C programmer so please bare with my stupidity.

Offline

#2 2008-06-15 02:50:44

GogglesGuy
Member
From: Rocket City
Registered: 2005-03-29
Posts: 610
Website

Re: link librt explicitly with -lrt switches.

jacko wrote:

the error I get is this during compile time.

You get a linker error, not a compile error...

jacko wrote:

all the googling searching leads me to believe explicitly telling the GNU linker (ld) to use the -lrt switches is all i need for the fix. Can anyone tell me how I can do that. Or how else I may solve this little issue. I am not a C programmer so please bare with my stupidity.

Yes you need to link to librt as the manpage of clock_gettime says...
So just add -lrt to your link line:

gcc -o nexuiz-dedicated builddate.c sys_linux.o vid_null.o snd_null.o cd_null.o cd_shared.o cl_collision.o cl_demo.o cl_dyntexture.o cl_gecko.o cl_input.o cl_main.o cl_parse.o cl_particles.o cl_screen.o cl_video.o clvm_cmds.o cmd.o collision.o common.o console.o csprogs.o curves.o cvar.o dpvsimpledecode.o filematch.o fractalnoise.o fs.o gl_backend.o gl_draw.o gl_rmain.o gl_rsurf.o gl_textures.o host.o host_cmd.o image.o image_png.o jpeg.o keys.o lhnet.o libcurl.o mathlib.o matrixlib.o mdfour.o menu.o meshqueue.o model_alias.o model_brush.o model_shared.o model_sprite.o mvm_cmds.o netconn.o palette.o polygon.o portals.o protocol.o prvm_cmds.o prvm_edict.o prvm_exec.o r_explosion.o r_lerpanim.o r_lightning.o r_modules.o r_shadow.o r_sky.o r_sprites.o sbar.o sv_demo.o sv_main.o sv_move.o sv_phys.o sv_user.o svbsp.o svvm_cmds.o sys_shared.o vid_shared.o view.o wad.o world.o zone.o -O2 -fno-strict-aliasing -march=i686 -mtune=generic -O2 -pipe -lm -ldl -lrt

Hope this helps!

Offline

#3 2008-06-15 06:45:09

sniffles
Member
Registered: 2008-01-23
Posts: 275

Re: link librt explicitly with -lrt switches.

Out of sheer curiosity, how come you're patching C code yet are not a C programmer?

Last edited by sniffles (2008-06-15 06:45:35)

Offline

#4 2008-06-15 09:25:38

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: link librt explicitly with -lrt switches.

sniffles wrote:

Out of sheer curiosity, how come you're patching C code yet are not a C programmer?

He already gave the explanation in the original post.
In any cases, I don't see how that is surprising, this happens all the time in open source.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#5 2008-06-15 09:55:40

sniffles
Member
Registered: 2008-01-23
Posts: 275

Re: link librt explicitly with -lrt switches.

shining wrote:
sniffles wrote:

Out of sheer curiosity, how come you're patching C code yet are not a C programmer?

He already gave the explanation in the original post.
In any cases, I don't see how that is surprising, this happens all the time in open source.

I see. Thanks.

Last edited by sniffles (2008-06-15 09:56:08)

Offline

#6 2008-06-15 11:40:04

jacko
Member
Registered: 2007-11-23
Posts: 840

Re: link librt explicitly with -lrt switches.

GogglesGuy wrote:

Yes you need to link to librt as the manpage of clock_gettime says...
So just add -lrt to your link line:

gcc -o nexuiz-dedicated builddate.c sys_linux.o vid_null.o snd_null.o cd_null.o cd_shared.o cl_collision.o cl_demo.o cl_dyntexture.o cl_gecko.o cl_input.o cl_main.o cl_parse.o cl_particles.o cl_screen.o cl_video.o clvm_cmds.o cmd.o collision.o common.o console.o csprogs.o curves.o cvar.o dpvsimpledecode.o filematch.o fractalnoise.o fs.o gl_backend.o gl_draw.o gl_rmain.o gl_rsurf.o gl_textures.o host.o host_cmd.o image.o image_png.o jpeg.o keys.o lhnet.o libcurl.o mathlib.o matrixlib.o mdfour.o menu.o meshqueue.o model_alias.o model_brush.o model_shared.o model_sprite.o mvm_cmds.o netconn.o palette.o polygon.o portals.o protocol.o prvm_cmds.o prvm_edict.o prvm_exec.o r_explosion.o r_lerpanim.o r_lightning.o r_modules.o r_shadow.o r_sky.o r_sprites.o sbar.o sv_demo.o sv_main.o sv_move.o sv_phys.o sv_user.o svbsp.o svvm_cmds.o sys_shared.o vid_shared.o view.o wad.o world.o zone.o -O2 -fno-strict-aliasing -march=i686 -mtune=generic -O2 -pipe -lm -ldl -lrt

Hope this helps!

Yes, but my question was where do I add in this -lrt for the linker. The linker program is LD and gcc is compiler. That is why I had no idea to add an -lrt to the end of the gcc command.

Plus, I was using the arch package and makepkg to compile the source.

this had me confused, until I checked the makefile.inc... LDFLAGS_UNIXCOMMON was the line I was looking for.

##### UNIX specific variables #####

OBJ_GLX= builddate.c sys_linux.o vid_glx.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON)

LDFLAGS_UNIXCOMMON=-lm -lrt
LDFLAGS_UNIXCL=-L$(UNIX_X11LIBPATH) -lX11 -lXpm -lXext -lXxf86dga -lXxf86vm $(LIB_SOUND)
LDFLAGS_UNIXCL_PRELOAD=-lz -ljpeg -lpng -lvorbis -lvorbisfile -lcurl -lmodplug
LDFLAGS_UNIXSV_PRELOAD=-lz -lcurl
LDFLAGS_UNIXSDL_PRELOAD=-lz -ljpeg -lpng -lvorbis -lvorbisfile -lcurl -lmodplug
CFLAGS_UNIX_PRELOAD=-DPREFER_PRELOAD

LDFLAGS_UNIXSDL=$(SDLCONFIG_LIBS) $(LIB_SND_MODPLUG)
EXE_UNIXCL=darkplaces-glx
EXE_UNIXSV=darkplaces-dedicated
EXE_UNIXSDL=darkplaces-sdl
EXE_UNIXCLNEXUIZ=nexuiz-glx
EXE_UNIXSVNEXUIZ=nexuiz-dedicated
EXE_UNIXSDLNEXUIZ=nexuiz-sdl

CMD_UNIXRM=rm -rf

The reason I am not a C programmer, took me 4 hours to figure that simple fix out.

Offline

Board footer

Powered by FluxBB