Ubuntu上对OpenGL的未定义引用

时间:2014-04-10 10:48:47

标签: opengl cmake glut freeglut

我得到了所有这些未定义的引用:

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

我正在使用cmake编译我的项目,并在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")

我在文件中包含以下内容:

#include <Gavam.h>

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

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

我做错了什么?

1 个答案:

答案 0 :(得分:2)

使用CMake标准模块FindOpenGL

代替链接器标志