【问题标题】:Undefined reference with FreeType 2FreeType 2 的未定义引用
【发布时间】:2013-01-01 13:13:15
【问题描述】:

我在使用FreeType 2 构建一个简单示例时遇到未定义的引用错误。

gcc `/usr/bin/freetype-config --cflags`  `/usr/bin/freetype-config --libs` a.c 
/tmp/ccuSpdkr.o: In function `main':
a.c:(.text+0x10): undefined reference to `FT_Init_FreeType'
collect2: error: ld returned 1 exit status

我使用的是 Ubuntu 12.10 x64。安装包 libfreetype6 & libfreetype6-dev。

文件a.c是:

#include <stdio.h>
#include <ft2build.h> 
#include FT_FREETYPE_H

int main() {
  FT_Library library;
  FT_Init_FreeType( &library );
  return 0;
}

我尝试了两步编译,以确保一切都在 64 位:

> gcc -c `/usr/bin/freetype-config --cflags` a.c
> file a.o
a.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
> /usr/bin/freetype-config --cflags
-I/usr/include/freetype2
> /usr/bin/freetype-config --libs
-L/usr/lib/x86_64-linux-gnu -lfreetype -lz
> file /usr/lib/x86_64-linux-gnu/libfreetype.so.6.9.0
/usr/lib/x86_64-linux-gnu/libfreetype.so.6.9.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x8ed223c2650372fc88b41fd348a72f03329adefa, stripped

我错过了什么?

【问题讨论】:

    标签: linux compilation linker freetype2


    【解决方案1】:

    您应该将链接器标志放在对象和/或源文件之后;而不是

    gcc `freetype-config --libs` a.c
    

    gcc a.c `freetype-config --libs`
    

    【讨论】:

    • 必须这样做的原因是什么?
    • 链接器按照符号包含文件的指定顺序查找符号。
    猜你喜欢
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 2020-07-10
    • 2012-06-29
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多