【问题标题】:How add OpenGL & GLUT for CLion on Windows?如何在 Windows 上为 CLion 添加 OpenGL 和 GLUT?
【发布时间】:2020-12-27 17:18:22
【问题描述】:

我已经安装了 OpenGL 和 Glut,但是当我尝试运行它时 - 出现此错误。我是不是安装错了?还是我应该编辑 CMake 文件?

CMakeLists.txt:

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

【问题讨论】:

    标签: c++ windows opengl clion glut


    【解决方案1】:

    add_custom_target 中的命令在工作目录设置为您的构建目录的情况下执行。因此,您提供的相对路径被解释为相对于构建目录。

    要么将工作目录设置为CMAKE_CURRENT_SOURCE_DIR,要么使用它将相对路径转换为复制命令中的绝对路径。

    【讨论】:

    • 谢谢!但我也遇到了一个错误Error copying file "CMAKE_CURRENT_SOURCE_DIR/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
    • 是变量,所以需要写${CMAKE_CURRENT_SOURCE_DIR}。我没有提到这一点,因为您已经在 cmake 文件中使用了变量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2011-11-04
    • 1970-01-01
    相关资源
    最近更新 更多