我试图让OpenGL在CLion中工作,从freeglut下载bin / include / library文件并将其复制到minGW。它们在那里,CLion在编译时正在使用该minGW文件夹,但是,当它尝试编译freeglut提供的测试代码时,它将返回“严重错误:GL / glut.h:没有这样的文件或目录#include <GL/glut.h>
“
我已经尝试了不同版本的CMakeLists,它们都返回相同的问题。如果将GL文件夹复制到项目旁边,则会得到大量未定义的引用。
尝试此CMakeList后,出现相同的错误。 (来自Running Opengl program with CLion IDE)
cmake_minimum_required(VERSION 3.14)
project(gltest)
set(CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_FLAGS "-lglut")
set (CMAKE_CXX_FLAGS "-lGL")
set (CMAKE_CXX_FLAGS "-lGLU")
include_directories(GL/)
add_executable(gltest Callbacks.c HelloGLUT.c)
target_link_libraries(gltest -lglut -lGL -lGLU)
更新
使用新的CMakeList(如注释中所建议的那样,我非常感谢您在这里的好人),我得到了一些新的错误,但是CLion现在似乎可以访问GL库了。
CMakeList:
cmake_minimum_required(VERSION 3.14)
project(gltest)
set(SOURCE_FILES Callbacks.c HelloGLUT.c)
set(OPENGL_INCLUDE_DIR C:/minGW/mingw64/include)
set(OPENGL_LIBRARY C:/minGW/mingw64/lib)
find_package(OPENGL REQUIRED)
add_executable(gltest ${SOURCE_FILES})
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(gltest ${OPENGL_LIBRARY} )
错误:
CMakeFiles\gltest.dir/objects.a(Callbacks.c.obj): In function "glutInit_ATEXIT_HACK':
C:/minGW/mingw64/include/GL/freeglut_std.h:637: undefined reference to "__imp___glutInitWithExit"
CMakeFiles\gltest.dir/objects.a(Callbacks.c.obj): In function "glutCreateWindow_ATEXIT_HACK":
还有几个未定义的引用,以相同的方式引用了各种“ __imp___glut”函数。有什么想法吗?
如果我使用target_link_libraries(gltest ${OPENGL_LIBRARY} glut GL GLU)
,我会得到
“ C:/ minGW / mingw64 / bin /../ lib / gcc / x86_64-w64-mingw32 / 8.1.0 /../../../../ x86_64-w64-mingw32 / bin / ld.exe :找不到-lglut“,与lGL和lGLU相同
答案 0 :(得分:-1)
遇到相同错误的解决方案
确保您遵循自述文件,并在mingw内的DIFFERENT文件夹中安装了freeglut(对我来说,这是C:/ minGW / mingw64 / freeglut),然后在其中复制freeglut的include和lib。确保您有一个FindFREEGLUT.cmake文件(如果有下载,则我只能从https://git.omkov.net/Jamozed/Chip8Emulator/releases中提取该文件,并且可以自由发布该文件)。将FindFREEGLUT.cmake复制到项目目录,例如“ C:/CLionProjects/gltest/cmake/FindFREEGLUT.cmake”。在此之后,我使用了以下CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(gltest)
set(SOURCE_FILES Callbacks.c HelloGLUT.c)
set(GLUT_INCLUDE_DIR "C:/minGW/mingw64/freeglut/include")
set(OPENGL_LIBRARY_DIR "C:/minGW/mingw64/freeglut/lib")
# GLUT
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIR})
if(NOT GLUT_FOUND)
message(ERROR "GLUT not found!")
endif(NOT GLUT_FOUND)
# OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
if(NOT OPENGL_FOUND)
message(ERROR "OPENGL not found!")
endif(NOT OPENGL_FOUND)
add_executable(gltest ${SOURCE_FILES})
target_link_libraries(gltest ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})