问题描述
我正在尝试将GLFW链接到我的C程序.
I am trying to link GLFW to my C program.
文档似乎建议使用#include<GLFW/glfw3.h>
,但是我已经安装了2.7.2(从发行版的存储库中)并且没有该头文件:
The docs seem to suggest #include<GLFW/glfw3.h>
however I have installed 2.7.2 (from my distro's repository) and don't have that header file:
find / -name *glfw* 2> /dev/null
/usr/lib/libglfw.so.2.6
/usr/lib/libglfw.a
/usr/lib/libglfw.so
/usr/lib/pkgconfig/libglfw.pc
/usr/lib/libglfw.so.2
/usr/include/GL/glfw.h
/usr/share/doc/libglfw-dev
/usr/share/doc/libglfw2
/var/cache/apt/archives/libglfw2_2.7.2-1_i386.deb
/var/cache/apt/archives/libglfw-dev_2.7.2-1_i386.deb
/var/lib/dpkg/info/libglfw2.list
/var/lib/dpkg/info/libglfw2.postinst
/var/lib/dpkg/info/libglfw-dev.md5sums
/var/lib/dpkg/info/libglfw2.postrm
/var/lib/dpkg/info/libglfw2.md5sums
/var/lib/dpkg/info/libglfw2.shlibs
/var/lib/dpkg/info/libglfw-dev.list
我尝试了#include<GL/glfw.h>
,但仍然得到undefined reference to 'glfwLoadTexture2D'
I tried #include<GL/glfw.h>
but I still get undefined reference to 'glfwLoadTexture2D'
如何链接到GLFW并使用glfwLoadTexture2D()
?
How do I link to GLFW and use glfwLoadTexture2D()
?
推荐答案
#include
对链接器不执行任何操作.它只会带来声明,而不是实际功能.
An #include
does nothing for the linker; it just brings in declarations, not the actual functions.
文档指示GLFW使用 pkg-config (不足为奇; 知道她的东西),因此您的编译行应类似于:
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`
还请注意,由于该库使用pkg-config
,因此您不应该关心"诸如头文件和库文件在特定安装中的位置之类的详细信息.只需使用--cflags
和--libs
模式询问,就可以返回正确的位置,如上面的示例所示.
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.
这篇关于我如何链接GLFW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!