Dav*_*nes 3 c linker shared-libraries freetype
来自PHP,这是我第一次使用C/C++(所以对我来说很容易).我正在按照本教程使用FreeType库编写一个简单的脚本.以下编译就好了:
#include <ft2build.h>
#include FT_FREETYPE_H
main() {
FT_Library library;
FT_Face face;
}
Run Code Online (Sandbox Code Playgroud)
这告诉我FreeType库随时可供编译器使用.但是,一旦我尝试使用任何方法,事情就会破裂.例如,采用以下脚本:
#include <ft2build.h>
#include FT_FREETYPE_H
main() {
int error;
FT_Library library;
error = FT_Init_FreeType(&library);
if (error) {}
FT_Face face;
error = FT_New_Face(library, "/usr/share/fonts/truetype/arial.ttf", 0, &face);
if (error == FT_Err_Unknown_File_Format) {
printf("Font format is unsupported");
} else if (error) {
prinft("Font file is missing or corrupted");
}
}
Run Code Online (Sandbox Code Playgroud)
此脚本在编译时产生以下错误:
#gcc render.c -I/usr/include/freetype2
/tmp/cc95255i.o: In function `main':
render.c:(.text+0x10): undefined reference to `FT_Init_FreeType'
render.c:(.text+0x30): undefined reference to `FT_New_Face'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Sco*_*ter 13
这些都是链接错误.如果它们包含带有演示的Makefile,那么最好使用它.否则,您需要在编译命令行中添加-L和-l选项,以便编译器(实际上是由场景后面的编译器调用的链接器)知道在哪里可以找到FreeType库.
-L选项提供了库的代码所在的路径.例如
-L/usr/local/lib
Run Code Online (Sandbox Code Playgroud)
-l选项提供库的名称.使用-l选项命名的库以缩写形式指定,即从前面的"lib"和后面的".a"中删除.因此,例如,如果FreeType库存储在文件libfreetype.a中,它将在-l选项中显示为
-lfreetype
Run Code Online (Sandbox Code Playgroud)
例如:
gcc render.c -I/usr/include/freetype2 -L/usr/local/lib -lfreetype
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12157 次 |
最近记录: |