c++ - 编译 GLFW 时遇到问题, undefined symbol

标签 c++ macos opengl cmake clion

我正在阅读 this tutorial on OpenGL .我收到如下编译错误:

Undefined symbols for architecture x86_64:
  "_glfwInit", referenced from:
      _main in main.cpp.o
  "_glfwTerminate", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [OpenGL] Error 1
make[2]: *** [CMakeFiles/OpenGL.dir/all] Error 2
make[1]: *** [CMakeFiles/OpenGL.dir/rule] Error 2
make: *** [OpenGL] Error 2

现在我将列出我当前的设置,从我的 main.cpp 开始

#include <iostream>
#include <GLFW/glfw3.h>
#include <thread>

int main() {
    glfwInit();
    std::this_thread::sleep_for(std::chrono::seconds(1));
    glfwTerminate();
    return 0;
}

这是我的 Cmake 文件

cmake_minimum_required(VERSION 3.7)
project(OpenGL)

set(CMAKE_CXX_STANDARD 11)

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

最后是我的命令行参数:

-lglfw -framework Cocoa -framework OpenGL -
framework IOKit -framework CoreVideo 

我正在使用 CLion,我相信我已经正确编译了它。我只是想获得一个空白窗口。

最佳答案

如果您使用的是 CMake,为什么要在命令行上指定库?为此,将 target_link_libraries 指令放入您的 CMakeLists.txt

关于c++ - 编译 GLFW 时遇到问题, undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43817344/

相关文章:

macos - Valgrind Mac OS Sierra 10.12.1

macos - 在 NSBitmapImageRep 上绘图

c++ - 如何在这种情况下适本地使用 RAII/减少内存泄漏

c++ - 为 C++ 选择 begin() 和 end()

macos - 如何使用 Free Pascal 编译 64 位 Mac 程序?

c++ - Visual Studio 2015 (C++) 代码大小

c++ - 在没有窗口的情况下使用 OpenGL

c# - 试图设置 VBO :s in C# using TAO and OpenGL TK framework

C++ 新手,出现编译错误(linux、g++ 编译器)

c++ - 为什么有人会使用#define 来定义常量?