本文介绍了如何添加OpenGL&GLUT for Windows上的CLion?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了OpenGL和Glut,但是当我尝试运行它时-出现此错误.我安装错了吗?还是应该编辑CMake文件?
I have installed OpenGL and Glut but when I'm trying to run it - get this error. Have I installed something wrong? Or should I edit CMake file?
project(LW1)
set(CMAKE_CXX_STANDARD 17)
include_directories(OpenGL)
include_directories(OpenGL/include) # OpenGL/include has to contain the required OpenGL's .h files
include_directories(OpenGL/lib) # OpenGL/lib has to contain the required OpenGL's .lib files
add_custom_target(glutdlllib
COMMAND ${CMAKE_COMMAND} -E copy LW1/OpenGL/dll/glut32.dll ${CMAKE_BINARY_DIR}
)
set(OpenGlLibs glaux glu32 glui32 glut32 opengl32 )
#These 3 lines are just linking and making executables
add_executable(LW1 main.cpp)
target_link_libraries(LW1 ${OpenGlLibs})
add_dependencies(LW1 glutdlllib)
target_link_libraries(LW1 -lOpenGL32 -lfreeGLUT)
main.cpp:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <glut.h>
void resize(int width, int height)
{
}
void display(void) {
glColor3d(1,1,0);
glutSolidSphere(1.0, 25, 25);
glFlush();
}
void init(void) {
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);;
glLoadIdentity();
glOrtho(-5.0, 5.0, -5.0, 5.0, 2.0, 12.0);
gluLookAt(0,0,5, 0,1,0, 0,1,0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char ** argv) {
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(50, 10);
glutInitWindowSize(400, 400);
glutCreateWindow("Hello");
glutReshapeFunc(resize);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
错误:
"C:\Program Files\JetBrains\CLion 2020.2.1\bin\cmake\win\bin\cmake.exe" --build C:\Users\Anichaaaaaa\CLionProjects\LW1\cmake-build-debug --target LW1 -- -j 6
Error copying file "LW1/OpenGL/dll/glut32.dll" to "C:/Users/Anichaaaaaa/CLionProjects/LW1/cmake-build-debug".
mingw32-make.exe[3]: *** [CMakeFiles\glutdlllib.dir\build.make:76: CMakeFiles/glutdlllib] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:96: CMakeFiles/glutdlllib.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:130: CMakeFiles/LW1.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:150: LW1] Error 2
推荐答案
add_custom_target
中的命令是在将工作目录设置为构建目录的情况下执行的.因此,您给出的相对路径将被解释为相对于构建目录.
The command in add_custom_target
is executed with the working directory set to your build directory. The relative path you give is thus interpreted as relative to the build directory.
将工作目录设置为 CMAKE_CURRENT_SOURCE_DIR
或使用它在复制命令中将相对路径转换为绝对路径.
Either set the working directory to CMAKE_CURRENT_SOURCE_DIR
or use it convert the relative path to an absolute one in your copy command.
这篇关于如何添加OpenGL&GLUT for Windows上的CLion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!