Segfault on very simple source

I'm trying to write a simple script using the FreeType library. The segfault is occurring during execution of the FT_Set_Pixel_Sizes method, though I'm using it correctly. Any help would be great. Here's the full code:

#include <ft2build.h>
#include FT_FREETYPE_H

main() {

    FT_Library library;
    FT_Face face;
    FT_GlyphSlot slot;
    FT_UInt glyph_index = 30;
    char* font_file = "/usr/share/fonts/truetype/freefont/FreeMono.ttf";

    // Render font
    FT_New_Face(library, font_file, 0, &face);

    FT_Set_Pixel_Sizes(face, 0, 16); /* THIS LINE IS CAUSING THE SEGFAULT */

    slot = face->glyph;
    FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
    FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);


You did not initialize your Library variable : see FT_LIBRARY documentation. You should use FT_Init_FreeType :


Defined in FT_FREETYPE_H (freetype/freetype.h).

FT_EXPORT( FT_Error ) FT_Init_FreeType( FT_Library *alibrary );

Initialize a new FreeType library object. The set of modules that are registered by this function is determined at build time.

output alibrary A handle to a new library object.

return FreeType error code. 0 means success.

You could first get used to this library following this tutorial. Take care to check the return values too ...

Need Your Help

Outputting long fixed-width records to a flat file using SSIS

sql-server-2005 ssis fixed-width

I have to build an SSIS package for work that takes the contents of a table, all columns, and outputs it to a flat file. The problem is, one of the columns is a varchar(5100) and that puts the tot...

Adding Bonjour (dns_sd.h) library to Qt in Windows

windows qt bonjour

I've been trying to properly add the open source dns_sd.h library provided by Apple. I am writing a program that uses the BonjourRegistrar class as demonstrated here:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.