Hey guys,

So I have compiled my first home-written static library (named PixGUI) that happens to call OpenGL functions. However, I noticed that when compiling (using MinGWs GCC with Code::Blocks project set to "static library") it doesn't matter whether I supply the linker with libopengl32.a or not, it simply compiles each time.

However, when I link PixGUI to another project, i.e. Pixlings, and try to compile that, it gives me these errors:

||=== Pixlings, Release ===|
..\PixGUI\lib\libPixGUI.a(button.o):button.cpp:(.text+0xc1)||undefined reference to `glColor3fv@4'|
..\PixGUI\lib\libPixGUI.a(button.o):button.cpp:(.text+0xea)||undefined reference to `glRectf@16'|
||=== Build finished: 2 errors, 0 warnings ===|

The build log of libPixGUI.a (without supplying the linker with opengl32, but doesn't matter for undefined references)

-------------- Build: Release in PixGUI ---------------

Compiling: element.cpp
Compiling: engine.cpp
Compiling: window.cpp
Compiling: button.cpp
Linking static library: lib\libPixGUI.a
ar.exe: creating lib\libPixGUI.a
Output size is 39.72 KB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings

Build log of Pixlings

-------------- Build: Debug in Pixlings ---------------

Compiling: Program.cpp
Compiling: game.cpp
Compiling: main.cpp
Compiling: Menu.cpp
Linking console executable: bin\Debug\Pixlings.exe
..\PixGUI\lib\libPixGUI.a(button.o):button.cpp:(.text+0xc1): undefined reference to `glColor3fv@4'
..\PixGUI\lib\libPixGUI.a(button.o):button.cpp:(.text+0xea): undefined reference to `glRectf@16'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings

How would I solve these undefined references?

Recommended Answers

All 2 Replies

Well I'd say you're probably not prototyping the functions you want to use from your library properly. Did you write a head file for your library and extern the prototypes?

Hehe, I messed up the linking order.

Say that Program A depends on Lib B, and A and B contain references to Lib C, then A needs to supply B before C, not after.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.