How do I link GLFW

*爱你&永不变心* 提交于 2019-12-02 07:05:38
unwind

An #include does nothing for the linker; it just brings in declarations, not the actual functions.

The documentation indicates that GLFW uses pkg-config (not surprising; @elmindreda knows her stuff), so your compilation line should be something like:

$ cc `pkg-config --cflags glfw3` -o foo foo.c `pkg-config --static --libs glfw3`

Also note that since the library uses pkg-config, you're not supposed to "care" about details such as where the header and library files are located on your particular installation. Just ask using the --cflags and --libs modes, and you will get the proper locations returned, as the example above indicates.

You are mixing up compilation and linking. If you were missing headers, you would probably have errors a lot sooner than the linking stage.

"Undefined reference" results from symbols not being found by the linker. The most likely cause is you not telling gcc that it should link to the GLFW libraries:

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