问题
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