C编译器错误:未定义引用'FT_Init_FreeType“ [英] C compiler error: Undefined reference to 'FT_Init_FreeType'

查看:3463
本文介绍了C编译器错误:未定义引用'FT_Init_FreeType“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从PHP的到来,这是我用C / C ++初体验(这样下去容易对我)。我下面的本教程编写使用FreeType库一个简单的脚本。下面编译就好了:

Coming from PHP, this is my first experience with C/C++ (so go easy on me). I'm following this tutorial to write a simple script using the FreeType library. The following compiles just fine:

#include <ft2build.h>
#include FT_FREETYPE_H

main() {
    FT_Library library;
    FT_Face face;
}

这告诉我,FreeType库是现成的编译器。然而,事情一旦突破我尝试使用任何方法。例如,以下面的脚本:

This tells me that the FreeType library is readily available to the compiler. However, things break once I try to use any methods. For example, take the following script:

#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");
    }
}

本脚本编译时产生以下错误:

This script produces the following error upon compiling:

#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

任何想法?

推荐答案

这些都是链接错误。如果他们包括与演示一个Makefile你还是使用更好。否则,你需要-L和-l选项添加到您的编译命令行所以编译器(实际上是链接程序)知道在哪里可以找到FreeType库。

Those are link errors. If they include a Makefile with the demo you are better off using that. Otherwise, you need to add -L and -l options to your compile command line so the compiler (actually linker) knows where to find the FreeType library.

-L选项给出了路径,其中code的库是否存在。例如:

The -L option gives the path to where the code for the library exists. For example

-L/usr/local/lib  

和-l选项给库的名称。在缩短的形式指定使用-l选项命名的图书馆,那是你在前面和后面的。一个假关闭LIB。因此,例如,如果FreeType库存储在文件libfreetype.a,它会显示在-l选项作为

And the -l option gives the name of the library. The library named with the -l option is specified in a shortened form, that is you leave off the "lib" in the front and the ".a" in the back. So for example, if the FreeType library was stored in file libfreetype.a , it would show in the -l option as

-lfreetype

例如:

gcc render.c -I/usr/include/freetype2 -L/usr/local/lib -lfreetype

这篇关于C编译器错误:未定义引用'FT_Init_FreeType“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆