无法编译GLFW,未定义符号 [英] Trouble compiling GLFW, undefined symbols

查看:523
本文介绍了无法编译GLFW,未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在阅读关于OpenGL的本教程.我收到如下编译错误:

I'm currently reading this tutorial on OpenGL. I'm getting compile errors as follows:

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开始列出当前设置

Now I'll list my current setup, starting with my 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文件

Here's my Cmake file

cmake_minimum_required(VERSION 3.7)
project(OpenGL)

set(CMAKE_CXX_STANDARD 11)

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

最后是我的命令行参数:

And finally my command line arguments:

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

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

I'm using CLion, and I believe I've compiled it correctly. I'm just trying to get a blank window.

推荐答案

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

Why are you specifying libraries on the command line if you're using CMake? Put a target_link_libraries directive into your CMakeLists.txt for that.

这篇关于无法编译GLFW,未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆