Code::Blocks Forums

User forums => Help => Topic started by: Wecali on December 15, 2007, 01:39:45 am

Title: Problems with including some headers
Post by: Wecali on December 15, 2007, 01:39:45 am
Hi,

I'm new at Codeblocks and I try to get this example (http://www.freetype.org/freetype2/docs/tutorial/example1.c) of the FreeType2 Documentation (http://www.freetype.org/freetype2/docs/tutorial/step1.html) working. The problem might be too easy for you, but as a beginner I have problems in understanding these error messages:

Code
-------------- Build: Debug in test ---------------

Linking console executable: bin\Debug\test.exe
obj\Debug\example1.o: In function `main':
Y:/test/test/example1.c:98: undefined reference to `FT_Init_FreeType'
Y:/test/test/example1.c:101: undefined reference to `FT_New_Face'
Y:/test/test/example1.c:105: undefined reference to `FT_Set_Char_Size'
Y:/test/test/example1.c:125: undefined reference to `FT_Set_Transform'
Y:/test/test/example1.c:128: undefined reference to `FT_Load_Char'
Y:/test/test/example1.c:144: undefined reference to `FT_Done_Face'
Y:/test/test/example1.c:145: undefined reference to `FT_Done_FreeType'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
7 errors, 0 warnings

What I know is that all the errors are functions. The first function is "FT_Init_FreeType" which is here:
Code
  error = FT_Init_FreeType( &library );              /* initialize library */ //
  /* error handling omitted */

  error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
  /* error handling omitted */

  /* use 50pt at 100dpi */
  error = FT_Set_Char_Size( face, 50 * 64, 0,
                            100, 0 );                /* set character size */
  /* error handling omitted */

  slot = face->glyph;


I have added the Path Y:\freetype-2.3.5\freetype-2.3.5 with Freetype Headers to the Compiler Search Directories, which can be found under Settings-->Compiler and Debugger Settings-->Search Directories-->Compiler. Thus, MingGW should be able to find all the necessary things to compile that example properly.

The FreeType Headers are included with:

Code
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <ft2build.h>
#include FT_FREETYPE_H

After reading websites related to linkers, I assume that it perhaps has something to do with a missing dll or so where the missing functions can be found. As said before I'm new at Codeblocks and i have never changed something in the compiler options before.

Can anyone tell me why these error messages occur?
Title: Re: Problems with including some headers
Post by: thomas on December 15, 2007, 01:53:03 am
This error ("undefined reference") has nothing to do with headers, but with libraries/object files.

You have to link to the freetype library too, only including headers isn't enough (this is not a peculiarity of freetype, but applies in general).
Title: Re: Problems with including some headers
Post by: Wecali on December 15, 2007, 02:18:09 am
Thank you very much.

I have found a Freetype6.dll in a binary downloaded from freetype.org. I think i have to tell the linker somehow that he should use this file, but there is no .lib or something else what i can add as a library to the linker settings in "Compiler and debugger settings".

I guess that I have to add -lfreetype to the linker options on the right site as well. But it won't compile because the linker doesn't know -lfreetype.
Title: Re: Problems with including some headers
Post by: thomas on December 15, 2007, 03:08:09 pm
Haven't used freetype for over 2 years and don't remember therefore :(

But, yes... you need to add the library with something like -lfreetype6 (if your DLL is called freetype6.dll). If you don't have an import library, you may also have to use --enable-auto-import.

There is a freetype build that's based on MinGW... I just don't remember where it was, but I'm sure there is (used it myself). It's a pretty all-in-one complete package with import lib, headers, and all... works unpack-compile-run without any pain. If you google for 5-10 minutes, you can sure find it.