Linker error : undefined reference to symbol 'glOrtho'

冷暖自知 提交于 2019-11-28 08:37:05

You need to link the OpenGL library:

g++ p1.cpp -lglut -lGL

You have not linked the OpenGL lib, where glOrtho() is defined. To make it work, compile/link with g++ p1.cpp -lglut -lGL. Mind the order of linking libs, as it is important in ld (linker used by g++). The GLUT library depends on OpenGL, and so -lGL HAS TO go after -glut. This is because ld only makes one cycle through the libraries, and thus if you linked -lGL -lglut, references from lglut to lGL will not be defined, thus making a linking error. Sorry for such a long answer, but I hope you'll learn something from it.

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