You are not logged in.
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
-lrt is correct, but make sure it comes after the objects in the link command, i.e. g++ src/*.o -lrt -l...
Offline
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
I'd change your makefile to:
LDFLAGS=-L # is this even necessary?
LDADD=-lrt ...
...
$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJECTS) $(LDADD)
Offline
Thanks, that fixed it.
Offline