Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EGL linker errors

I'm trying to link a really simple GLES2 & EGL program using g++ 4.9.1, on a Ubuntu Trusty system. I'm using the mesa libraries.

I'm getting linker errors for EGL functions:

test.cpp:(.text+0x342): undefined reference to `eglGetDisplay'
test.cpp:(.text+0x389): undefined reference to `eglInitialize'
test.cpp:(.text+0x40f): undefined reference to `eglCreateContext'
test.cpp:(.text+0x458): undefined reference to `eglCreatePbufferSurface'
test.cpp:(.text+0x49e): undefined reference to `eglMakeCurrent'

I am compiling test.cpp with

g++ -std=c++0x -Wall -Werror -lEGL -lGLESv2 -o test test.cpp 

I've tried switching the order of libraries, which sometimes matters, but I get the same problem. Is there a library I'm missing here?

I've run readelf -Ws /usr/lib/x86_64-linux-gnu/mesa-egl/libEGL.so and all of the required functions are defined.

like image 254
Anthony Avatar asked Feb 22 '15 06:02

Anthony


2 Answers

You should put libraries to the end of a command line

g++ -std=c++0x -Wall -Werror -o test test.cpp -lEGL -lGLESv2
like image 168
Maksym Davydov Avatar answered Nov 10 '22 18:11

Maksym Davydov


I managed to fix this by compiling the C++ file to an object file, and then linking as a separate step. I'm not sure why this works, when the one-line compilation doesn't.

g++ -std=c++0x -Wall -Werror -c -o test.o test.cpp 
g++ -o test test.o -lGLESv2 -lEGL

I've put the question to the community to try to figure out why: Single-command compile and link fails, separate steps work

like image 4
Anthony Avatar answered Nov 10 '22 18:11

Anthony