News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Problems with including some headers

Started by Wecali, December 15, 2007, 01:39:45 AM

Previous topic - Next topic

Wecali

Hi,

I'm new at Codeblocks and I try to get this example of the FreeType2 Documentation working. The problem might be too easy for you, but as a beginner I have problems in understanding these error messages:


-------------- 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:

  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:


#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?

thomas

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).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Wecali

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.

thomas

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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."