Undefined references to OpenGL on Ubuntu

青春壹個敷衍的年華 提交于 2021-01-28 06:48:00

问题


I'm getting all these undefined references:

Linking CXX executable SimpleGavam
../../lib/local/Gavam/libGavam.a(MeshUtils.cpp.o): In function `Gavam::DrawMesh(cv::Mat_<float>&, cv::Mat_<float> const&, cv::Mat_<int> const&, cv::Vec<double, 6> const&, double, double, double, double, cv::Size_<int> const&, double, double)':
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:189: undefined reference to `glutSwapBuffers'
../../lib/local/Gavam/libGavam.a(MeshUtils.cpp.o): In function `Gavam::InitialiseOpenGLDrawingWindow(int, int, double, double, double)':
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:578: undefined reference to `glutInit'
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:580: undefined reference to `glutInitDisplayMode'
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:582: undefined reference to `glutInitWindowSize'
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:584: undefined reference to `glutCreateWindow'
/home/samuel/Clm-Z/lib/local/Gavam/src/MeshUtils.cpp:585: undefined reference to `glutHideWindow'
collect2: error: ld returned 1 exit status
make[2]: *** [exe/SimpleGavam/SimpleGavam] Error 1
make[1]: *** [exe/SimpleGavam/CMakeFiles/SimpleGavam.dir/all] Error 2

I'm using cmake to compile my project and I've added the glut flags in CMakeLists

SET( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -g -std=c++11 -lGL -lglut -lGLU")
SET( CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -g -std=c++11 -lGL -lglut -lGLU")

I have these includes in the files:

#include <Gavam.h>

#include <math.h>
#include <fstream>

// OPEN GL
#include <GL/gl.h>
#include <GL/freeglut.h>

What am I doing wrong?


回答1:


Instead of the linker flags, use CMake Standard Module FindOpenGL



来源:https://stackoverflow.com/questions/22985882/undefined-references-to-opengl-on-ubuntu

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