【问题标题】:Linked Error when using OpenGL and GLUT libraries in CLion (MacOS)在 CLion (MacOS) 中使用 OpenGL 和 GLUT 库时出现链接错误
【发布时间】:2019-10-19 19:53:13
【问题描述】:

我正在尝试在 CLion 中使用 OpenGL 和 GLUT。我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(Graphos)

set(CMAKE_CXX_STANDARD 17)

find_library(GLUT REQUIRED)
find_library(OpenGL REQUIRED)

include_directories(.)

add_executable(
        Graphos
        AdjacencyList.h
        main.cpp
        Node.h
        UsefulFunctions.h
        Macros.h
        Coordinates.h
        GraphDrawer.h
)

当我运行项目时,我收到以下链接器错误:

Undefined symbols for architecture x86_64: "_glClearColor", referenced from: ...

列出了几个 gl 和 glut 函数。

这是我编写的 OpenGL 代码:

GLvoid initGL() {
        glClearColor(0, 0, 0, 1);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
}

GLvoid initialize(int argc, char** argv) {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
        glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        glutInitWindowPosition(200,200);
        glutCreateWindow("Graphs");
        initGL();
}

请帮帮我。

【问题讨论】:

    标签: c++ opengl linker-errors glut clion


    【解决方案1】:
    cmake_minimum_required(VERSION 3.14)
    project(Graphos)
    
    set(CMAKE_CXX_STANDARD 17)
    
    add_executable(
            Graphos
            AdjacencyList.h
            main.cpp
            Node.h
            UsefulFunctions.h
            Macros.h
            Coordinates.h
            GraphDrawer.h
    )
    
    find_package(OpenGL REQUIRED)
    find_package(GLUT REQUIRED)
    
    # Included these two lines:
    
    include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
    target_link_libraries(Graphos ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
    

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 2020-12-27
      • 2020-05-14
      相关资源
      最近更新 更多