Reputation: 348
I am getting undefined reference error while building a simple example with 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
I am on Ubuntu 12.10 x64. Package libfreetype6 & libfreetype6-dev are installed.
File a.c
is:
#include <stdio.h>
#include <ft2build.h>
#include FT_FREETYPE_H
int main() {
FT_Library library;
FT_Init_FreeType( &library );
return 0;
}
I tried 2 step compilation, to make sure everything is on 64 bit:
> 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
What am I missing?
Upvotes: 3
Views: 3399
Reputation:
You should put the linker flags after the object and/or source files; instead of
gcc `freetype-config --libs` a.c
write
gcc a.c `freetype-config --libs`
Upvotes: 4