gpt4 book ai didi

c++ - 在 CLion 中使用 freeglut 在 OpenGL 中链接错误

转载 作者:可可西里 更新时间:2023-11-01 17:58:16 26 4
gpt4 key购买 nike

所以,我正在使用 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 提供的头文件中的函数。那为什么我的程序中没有定义这些函数呢?

最佳答案

我一直在努力解决同样的问题,并通过将以下行附加到 CMakeLists.txt 来解决它:

find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})

关于c++ - 在 CLion 中使用 freeglut 在 OpenGL 中链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39502392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com