0

I tried to compile my c++/opengl-project with the g++ command. (I need this since I want to recompile it on every target system with a second self-written program.)

But when I execute:

g++ -Iinclude -Isrc $(pkg-config --cflags freetype2) -L/usr/X11R6/lib -L/usr/lib $(pkg-config --libs glew) -lglut $(pkg-config --libs glu) $(pkg-config --libs freetype2) main.cpp  (some more source files) src/Vec4.cpp

I get lots of 'undefined references' for gl/glu/glut/glew-functions, so I guess something fails with the libs:

/tmp/ccUm2dEl.o: In function `Box::render()':
Box.cpp:(.text+0x6e8): undefined reference to `glEnable'
Box.cpp:(.text+0x72c): undefined reference to `glBindTexture'
Box.cpp:(.text+0x736): undefined reference to `glBegin'
...
TextureManager.cpp:(.text+0x23b): undefined reference to `glTexParameteri'
TextureManager.cpp:(.text+0x295): undefined reference to `glTexImage2D'
collect2: ld gab 1 als Ende-Status zurück

I did some research, but according to what I found out the above command should be correct. I checked the pkg-config-calls as well and they seem to work. Before I tried the g++ command I used the Codeblocks IDE to compile it and it worked. Here are my settings:

In Compiler settings|Other options:

`pkg-config --cflags freetype2`

In Linker settings|Link libraries:

glut

In Linker settings|Other linker options:

`pkg-config --libs glu`
`pkg-config --libs glew`
`pkg-config --libs freetype2`

In Search directories|Compiler:

include
src

My system (Ubuntu Precise):

$ uname -a
Linux andromeda 3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

$ g++ -dumpversion
4.6

glxinfo
GLX version: 1.4
OpenGL version string: 4.2.0 NVIDIA 304.43

Codeblocks-version: 10.04

Thanks in advice

3
  • 3
    Put your files (.cpp and .o) before the libraries you link to on the command line. Commented Nov 3, 2012 at 15:35
  • I don't see libGL being added. Try adding -lGL after the X11 libraries. Commented Nov 3, 2012 at 17:38
  • By the way, libGL is added with pkg-config --libs glu Commented Dec 9, 2012 at 20:12

1 Answer 1

1

The problem is most likely that you link in the wrong order. The GNU linker wants its libraries in kind of reverse order, so if you place the linker libraries last on the command line it should go better.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 If object or library A requires B, then A needs to before B in the command line. This holds for .o files and libs linked with -l.
library A requires B I already paid attention to that, but thanks. I put the libs to the end and it worked! Thanks, you saved my day. I never got an answer that fast on any other forum before, seems like stackoverflow is much more useful than I thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.