You are not logged in.

#1 2010-01-05 02:49:43

j2902
Member
Registered: 2009-12-21
Posts: 20

[Solved] undefined reference to `clock_gettime'

I'm trying to compile a program that worked fine on Ubuntu and windows.

Here is my makefile

CXXFLAGS=-Wall `sdl-config --cflags` `freetype-config --cflags`
LDFLAGS=-L -lrt -lGL -lGLU -lSDL -lSDL_mixer -lILU -lILUT `freetype-config --libs`
CLFAGS=$(CXXFLAGS)

CXX=g++
CC=g++
SOURCES=src/Camera.cpp src/Color.cpp src/Data.cpp src/Engine.cpp \
        src/FontRenderer.cpp src/Renderable.cpp src/Point.cpp src/PrimitiveNode.cpp \
        src/Scene.cpp src/SoundEngine.cpp src/Texture.cpp src/TexturedNode.cpp \
        src/Timer.cpp src/Utils.cpp \
        \
        src/Particles/Particle.cpp src/Particles/ParticleEmitter.cpp \
        src/Particles/ParticleEngine.cpp \
        \
        src/external/GLFT_Font.cpp \
        \
        main.cpp

TARGET= klas

OBJECTS=$(SOURCES:.cpp=.o)

all: $(TARGET)
$(TARGET): $(OBJECTS)
    $(CXX) $(LDFLAGS) -o $(TARGET) $(OBJECTS)

clean:
    rm -rf $(OBJECTS) $(TARGET)

Here is the output from make

$ make
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Camera.o src/Camera.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Color.o src/Color.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Data.o src/Data.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Engine.o src/Engine.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/FontRenderer.o src/FontRenderer.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Renderable.o src/Renderable.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Point.o src/Point.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/PrimitiveNode.o src/PrimitiveNode.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Scene.o src/Scene.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/SoundEngine.o src/SoundEngine.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Texture.o src/Texture.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/TexturedNode.o src/TexturedNode.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Timer.o src/Timer.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Utils.o src/Utils.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Particles/Particle.o src/Particles/Particle.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Particles/ParticleEmitter.o src/Particles/ParticleEmitter.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/Particles/ParticleEngine.o src/Particles/ParticleEngine.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o src/external/GLFT_Font.o src/external/GLFT_Font.cpp
g++ -Wall `sdl-config --cflags` `freetype-config --cflags`   -c -o main.o main.cpp
g++ -L -lrt -lGL -lGLU -lSDL -lSDL_mixer -lILU -lILUT `freetype-config --libs` -o klas src/Camera.o src/Color.o src/Data.o src/Engine.o src/FontRenderer.o src/Renderable.o src/Point.o src/PrimitiveNode.o src/Scene.o src/SoundEngine.o src/Texture.o src/TexturedNode.o src/Timer.o src/Utils.o src/Particles/Particle.o src/Particles/ParticleEmitter.o src/Particles/ParticleEngine.o src/external/GLFT_Font.o main.o # this needs a main
src/Timer.o: In function `klas::Timer::Timer()':
Timer.cpp:(.text+0x80): undefined reference to `clock_gettime'
Timer.cpp:(.text+0x96): undefined reference to `clock_gettime'
src/Timer.o: In function `klas::Timer::Timer()':
Timer.cpp:(.text+0xc0): undefined reference to `clock_gettime'
Timer.cpp:(.text+0xd6): undefined reference to `clock_gettime'
src/Timer.o: In function `klas::Timer::restart()':
Timer.cpp:(.text+0x112): undefined reference to `clock_gettime'
src/Timer.o:Timer.cpp:(.text+0x136): more undefined references to `clock_gettime' follow
collect2: ld returned 1 exit status
make: *** [klas] Error 1

It seems that everything compiles find; it's just the linking stage that is getting me.  I googled this and was told to add the library rt (-lrt); however, this hasn't appeared to help unless I am doing something completely wrong.

Thanks.

Last edited by j2902 (2010-01-06 02:09:27)

Offline

#2 2010-01-05 03:47:06

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: [Solved] undefined reference to `clock_gettime'

-lrt is correct, but make sure it comes after the objects in the link command, i.e. g++ src/*.o -lrt -l...

Offline

#3 2010-01-05 04:50:39

j2902
Member
Registered: 2009-12-21
Posts: 20

Re: [Solved] undefined reference to `clock_gettime'

Alright, is there a good way to do that with my current makefile?

Otherwise, it seems like I have to manually do it.

Thanks.

Offline

#4 2010-01-05 05:36:46

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: [Solved] undefined reference to `clock_gettime'

I'd change your makefile to:

LDFLAGS=-L # is this even necessary?
LDADD=-lrt ...

...

$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJECTS) $(LDADD)

Offline

#5 2010-01-06 02:09:01

j2902
Member
Registered: 2009-12-21
Posts: 20

Re: [Solved] undefined reference to `clock_gettime'

Thanks, that fixed it.

Offline

Board footer

Powered by FluxBB