c++ - How to compile glfw on OSX with cmake -


i'm using clion ide jetbrains compile small hello world application.

this full log of commands , errors when attempting compile:

/applications/clion.app/contents/bin/cmake/bin/cmake --build /users/brian/library/caches/clion12/cmake/generated/ac340afb/ac340afb/debug --target dunjun -- -j 4 [ 50%] building cxx object cmakefiles/dunjun.dir/src/main.cpp.o clang: warning: -framework cocoa: 'linker' input unused clang: warning: -framework opengl: 'linker' input unused clang: warning: -framework iokit: 'linker' input unused [100%] linking cxx executable dunjun undefined symbols architecture x86_64:   "_glfwcreatewindow", referenced from:       _main in main.cpp.o   "_glfwinit", referenced from:       _main in main.cpp.o   "_glfwmakecontextcurrent", referenced from:       _main in main.cpp.o   "_glfwpollevents", referenced from:       _main in main.cpp.o   "_glfwswapbuffers", referenced from:       _main in main.cpp.o   "_glfwterminate", referenced from:       _main in main.cpp.o   "_glfwwindowshouldclose", referenced from:       _main in main.cpp.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) make[3]: *** [dunjun] error 1 make[2]: *** [cmakefiles/dunjun.dir/all] error 2 make[1]: *** [cmakefiles/dunjun.dir/rule] error 2 make: *** [dunjun] error 2 

i realize prevent these errors have add flags compiler. other stackoverflow questions refrence correct command:

gcc -iglfw3/include/ -lglfw3/lib/ -lglfw3 -framework opengl -framework cocoa -framework iokit -framework corevideo main.c 

how through cmake? how can work under clion.

below cmakelists.txt reference:

cmake_minimum_required(version 3.3) project(dunjun)  set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11 -framework cocoa -framework opengl -framework iokit") set( cmake_exe_linker_flags  "${cmake_exe_linker_flags}" )  set(source_files     bin/debug/dunjun_game     include/dunjun/common.hpp     src/main.cpp     cmakelists.txt     readme.md)  add_executable(dunjun ${source_files}) include_directories(include) 

add -framework flags linker flags, not compile flags.

set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11") set(cmake_exe_linker_flags "${cmake_exe_linker_flags} -framework cocoa -framework opengl -framework iokit") 

Comments