EGL linker errors

蓝咒 提交于 2020-01-13 03:37:34

问题


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.


回答1:


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




回答2:


You should put libraries to the end of a command line

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


来源:https://stackoverflow.com/questions/28655099/egl-linker-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!