Trouble compiling GLFW, undefined symbols

拟墨画扇 提交于 2019-12-25 05:05:34

问题


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

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

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 

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


回答1:


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.



来源:https://stackoverflow.com/questions/43817344/trouble-compiling-glfw-undefined-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!