在 CLion (MacOS) 中使用 OpenGL 和 GLUT 库时出现链接错误

Linked Error when using OpenGL and GLUT libraries in CLion (MacOS)

我正在尝试在 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();
}

请帮帮我。

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})