2 kinghace kinghace 于 2017.11.30 14:41 提问

如何使用Cmake构建OpenGL项目?用的CLion编辑器

最近在学OpenGL,下面的是一个简单的画线段程序,可以在VS2017上面运行,但VS有点卡,于是试着在CLion上面运行。

 #include <stdlib.h>
#include <glut.h>

void init(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}

void lineSegment(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINES);
    glVertex2i(100, 0);
    glVertex2i(0, 75);
    glEnd();

    glFlush();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("测试");

    init();
    glutDisplayFunc(lineSegment);
    glutMainLoop();
}

CMakeList文件

 cmake_minimum_required(VERSION 3.8)
project(learnOpenGL)
set(CMAKE_CXX_STANDARD 11)

include_directories(C:/glut)
link_directories(C:/glut)

#find_library(libsrc glut C:/glut)
#message(${libsrc})

set(SOURCE_FILES main.cpp)
add_executable(learnOpenGL ${SOURCE_FILES})

#target_link_libraries( learnOpenGL ${libsrc})
target_link_libraries( learnOpenGL glut)

Build报错,如下?

 C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/glut/glut.lib when searching for -lglut
C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/glut/glut.dll when searching for -lglut
C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/glut/glut.lib when searching for -lglut
C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/glut/glut.dll when searching for -lglut
C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/glut\glut.lib when searching for -lglut
C:/PROGRA~1/DevCpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglut
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [learnOpenGL.exe] Error 1
CMakeFiles\learnOpenGL.dir\build.make:96: recipe for target 'learnOpenGL.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/learnOpenGL.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/learnOpenGL.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/learnOpenGL.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/learnOpenGL.dir/rule' failed
mingw32-make.exe: *** [learnOpenGL] Error 2
Makefile:117: recipe for target 'learnOpenGL' failed

折腾两天了,无论百度还是google都没有很好的实例。

1个回答

qq_20589257
qq_20589257   2017.11.30 18:45

找Cmake for CLion 的补丁 ,但是我没见过,哈哈哈

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!