我正在使用freeglut来进行一些OpenGL相关的操作,但是我一直遇到“未定义引用”的错误:
CMakeFiles\texture_mapping.dir/objects.a(TextureMapper.cpp.obj): In function `ZN13TextureMapper4initEv':
.../TextureMapper.cpp:20: undefined reference to `glClearColor@16'
.../TextureMapper.cpp:23: undefined reference to `glMatrixMode@4'
.../TextureMapper.cpp:24: undefined reference to `glLoadIdentity@0'
.../TextureMapper.cpp:25: undefined reference to `glOrtho@48'
CMakeFiles\texture_mapping.dir/objects.a(TextureMapper.cpp.obj): In function `ZN13TextureMapper7displayEv':
.../TextureMapper.cpp:45: undefined reference to `glClear@4'
...TextureMapper.cpp:48: undefined reference to `glColor3f@12'
...TextureMapper.cpp:49: undefined reference to `glBegin@4'
...TextureMapper.cpp:52: undefined reference to `glVertex3f@12'
...TextureMapper.cpp:53: undefined reference to `glVertex3f@12'
...TextureMapper.cpp:54: undefined reference to `glVertex3f@12'
...TextureMapper.cpp:55: undefined reference to `glVertex3f@12'
...TextureMapper.cpp:58: undefined reference to `glEnd@0'
...TextureMapper.cpp:61: undefined reference to `glFlush@0'
我正在使用MinGW和CLion进行这个项目。我认为我已经正确地完成了所有步骤。我将相关的文件移动到了MinGW的include
文件夹中,还有bin
文件夹和lib
文件夹。然后,在我的CMakeLists.txt
文件中添加了以下内容:
cmake_minimum_required(VERSION 3.3)
project(texture_mapping)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp TextureMapper.cpp TextureMapper.h Vertex.h ObjParser.cpp ObjParser.h)
add_executable(texture_mapping ${SOURCE_FILES})
target_link_libraries(texture_mapping libfreeglut.a libfreeglut_static.a)
我链接的库文件是freeglut唯一附带的库文件。
那么,我错过了什么?在编译之前,CLion没有显示任何错误。我甚至可以进入由freeglut提供的头文件中的函数。为什么这些函数在我的程序中没有定义呢?