Question

I am compiling with MinGW in Windows 7, using Code::Blocks as the IDE. Everything should be up to date. I noticed there are a number of similar questions, but those seemed to be about linking a dynamic library, not compiling the static library.

I am trying to use FTGL to be able to use text in OpenGL. FTGL requires FreeType 2 be installed. I downloaded the FreeType source, and followed the INSTALL.GNU instructions to build the static library from CMD.EXE, using mingw32-make.exe.

As the instructions indicated, I ran mingw32-make from the base directory of the FreeType installation. The console output was as expected:

D:\freetype-2.4.4>mingw32-make

FreeType build system -- automatic system detection

The following settings are used:

  platform                     win32
  compiler                     gcc
  configuration directory      .\builds\win32
  configuration rules          .\builds\win32\w32-gcc.mk

If this does not correspond to your system or settings please remove the file
'config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type 'make' again to build the library.
or 'make refdoc' to build the API reference (the latter needs python).

Could Not Find D:\freetype-2.4.4\objs\ftmodule.h
Generating modules list in ./objs/ftmodule.h...
"* module: truetype  (Windows/Mac font files with extension *.ttf or *.ttc)"
"* module: type1     (Postscript font files with extension *.pfa or *.pfb)"
"* module: cff       (OpenType fonts with extension *.otf)"
"* module: cid       (Postscript CID-keyed fonts, no known extension)"
"* module: pfr       (PFR/TrueDoc font files with extension *.pfr)"
"* module: type42    (Type 42 font files with no known extension)"
"* module: winfnt    (Windows bitmap fonts with extension *.fnt or *.fon)"
"* module: pcf       (pcf bitmap fonts)"
"* module: bdf       (bdf bitmap fonts)"
"* module: sfnt      (helper module for TrueType & OpenType formats)"
"* module: autofit   (automatic hinting module)"
"* module: pshinter  (Postscript hinter module)"
"* module: raster    (monochrome bitmap renderer)"
"* module: smooth    (anti-aliased bitmap renderer)"
"* module: smooth    (anti-aliased bitmap renderer for LCDs)"
"* module: smooth    (anti-aliased bitmap renderer for vertical LCDs)"
"* module: psaux     (Postscript Type 1 & Type 2 helper module)"
"* module: psnames   (Postscript & Unicode Glyph name handling)"
done.

Seeing as both the platform and compiler were correct, I ran the make command again:

D:\freetype-2.4.4>mingw32-make
(bunch of calls, building objects then linking them, until:)
ar: creating objs/freetype.a

This produced the file freetype.a in the directory D:\freetype-2.4.4\objs.

I then did the steps in Code::Blocks to link the library to the project, added a sample bit of code to test FTGL, and tried to build it.

I'm having two errors, depending on how I try to do things.

If I provide the correct directory to the linker (-LD:\freetype-2.4.4\objs), and link with -lfreetype, everything is fine until ld.exe quits with the error in the title, cannot find -lfreetype.

If I don't provide the correct directory, I get the same error. Can't find the library.

If I change the name of the file, freetype.a, to libfreetype.a, and provide the right directory, I instead get several undefined references.

obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x250): undefined reference to `FTPixmapFont::FTPixmapFont(char const*)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x258): undefined reference to `FTFont::Error() const'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x274): undefined reference to `FTFont::FaceSize(unsigned int, unsigned int)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x308): undefined reference to `FTFont::Render(char const*, int, FTPoint, FTPoint, int)'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x316): undefined reference to `FTPixmapFont::~FTPixmapFont()'
obj\Release\CApp_OnRender.o:CApp_OnRender.cpp:(.text+0x328): undefined reference to `FTPixmapFont::~FTPixmapFont()'
collect2: ld returned 1 exit status

If I provide the wrong directory, again I get the previous error that it couldn't find the library.

I found it odd that the make would, when following the directions in the install file, produce a library with a name that didn't start with lib. I checked and every single other .a file started with lib-. And it seems like the linker is looking for the file libfreetype.a. So why is the make creating freetype.a instead? This is using the same compiler for the library that I'm using to compile the program.

Anyway, not sure where to go from here. I thought of using the MSys shell that is part of the MinGW package, but I don't have much experience with it and the instruction in INSTALL.UNIX assume you know the more obvious commands. They mention using ./configure [options], without mention of what options might be advisable. Probably obvious to someone with more knowledge of the system, but MSys is my first experience with sh.

I'd appreciate any help with this matter.

Was it helpful?

Solution

My version of libfreetype.a (2.4.4, built from modified debian package) does not export the symbols your linker is looking for (FTPixmapFont constructor), nor do the headers declare such a class. A quick google search indicates they belong to FTGL.

Renaming your import file to libfreetype.a was correct (the mingw ld won't find it otherwise), but did you also link to the necessary FTGL libraries?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top