Skip to main content
GameDev.net gamedev.net
🔒 Locked

Short story: The nightmare of getting FreeType2 working

Started by MaulingMonkey Oct 22, 2004 at 10:55 AM 11 replies 3.5k views
Original Post
MaulingMonkey
MaulingMonkey
I give unto thee the brave adventures of MaulingMonkey in his attempts to create his own C++ GUI system. There once was a lad, by the name of MaulingMonkey. This lad was a nerd of some sort - quite ugly and smelly to boot. He said unto himself: "Why, I thinkst I wishest to create a C++ GUI for the game I plan to make!!! Let me start by getting some text working... but not only that, but text where I can get the sizes of letters and soforth so I might have automatic wrapping of text!" And so the young lad set forth to the great library of Google, and searched through it's massive archives, after which he came to a decision. "FreeType looks to be the tool I need - I'll just download it and try a small tutorial to make sure It's installed nicely!!" So MaulingMonkey downloaded and installed his new tool - he allready had the GNU C compiler installed, via his cygwin installation. And so the young lad compiled his example, and tested it out. Lo and behold it did not work! He got a run time error - something about not having enough room to grow the cygwin heap, and windows error "487". He tried many a DLL, googled for answers - he got some stuff about it being due to the DLL expecting to be run inside of cygwin - but running it inside the cygwin environment just provided DIFFERENT run time errors related to heap growth! And so the lad decided he would try to compile his fine DLL, since he had compiled many a DLL before, and hopefully by compiling it himself, he'd avoid the cygwin environment dependancies that plauged him! The lad knew what to do. He downloaded the source code from the website, unzipped it, and quickly brought up a command window. A few mishaps later, and he figure out how he was supposed to build his dll:
C:\freetype-2.1.9\>sh configure
...
...
...
C:\freetype-2.1.9\>make
...
...
...
C:\freetype-2.1.9\>make install
...
...
...
Which worked fine. He tested out the new DLL. Did it succeed? The poor lad was beginning to get quite fustrated after it reported the exact same heap error messages. "Why must you torment me so, oh great library!!! I must have downloaded thee, installed thee, and nurtured thee a thousand times by now!!!" After searching the great google library once more, the lad found some related email archives relating to cygwin and the GTK. Similar errors, fixed by setting CC to "gcc -mno-cygwin -mnatural-struct" (or something like that). So the lad decided to try again through the scripts:
C:\freetype-2.1.9\>set CC=gcc -mno-cygwin
C:\freetype-2.1.9\>set LD=ld -mno-cygwin
"So far, so good" said the lad.
C:\freetype-2.1.9\>sh configure
...
...
...
The lad noted the use of "gcc -mno-cygwin" in some of the tests the config script made. "Good good, this might just work after all!" said the lad.
C:\freetype-2.1.9\>make
...
...
...
The lad noted that -mno-cygwin was indeed being appended to all the invocations of gcc. He was glad that he was nearly done building a working DLL. C:\freetype-2.1.9\>make install ... ... ... The lad ran the command. And then all hell broke loose. Errors started streaming in:
lib /OUT:/cygdrive/c/freetype-2.1.9/objs/.libs/libfreetype.lib  /cygdrive/c/free
type-2.1.9/objs/ftsystem.o /cygdrive/c/freetype-2.1.9/objs/ftdebug.o /cygdrive/c
/freetype-2.1.9/objs/ftinit.o /cygdrive/c/freetype-2.1.9/objs/ftbase.o /cygdrive
/c/freetype-2.1.9/objs/ftbbox.o /cygdrive/c/freetype-2.1.9/objs/ftbdf.o /cygdriv
e/c/freetype-2.1.9/objs/ftglyph.o /cygdrive/c/freetype-2.1.9/objs/ftmm.o /cygdri
ve/c/freetype-2.1.9/objs/ftpfr.o /cygdrive/c/freetype-2.1.9/objs/ftstroke.o /cyg
drive/c/freetype-2.1.9/objs/fttype1.o /cygdrive/c/freetype-2.1.9/objs/ftwinfnt.o
 /cygdrive/c/freetype-2.1.9/objs/ftxf86.o /cygdrive/c/freetype-2.1.9/objs/autohi
nt.o /cygdrive/c/freetype-2.1.9/objs/bdf.o /cygdrive/c/freetype-2.1.9/objs/ftcac
he.o /cygdrive/c/freetype-2.1.9/objs/cff.o /cygdrive/c/freetype-2.1.9/objs/type1
cid.o /cygdrive/c/freetype-2.1.9/objs/ftgzip.o /cygdrive/c/freetype-2.1.9/objs/f
tlzw.o /cygdrive/c/freetype-2.1.9/objs/pcf.o /cygdrive/c/freetype-2.1.9/objs/pfr
.o /cygdrive/c/freetype-2.1.9/objs/psaux.o /cygdrive/c/freetype-2.1.9/objs/pshin
ter.o /cygdrive/c/freetype-2.1.9/objs/psnames.o /cygdrive/c/freetype-2.1.9/objs/
raster.o /cygdrive/c/freetype-2.1.9/objs/sfnt.o /cygdrive/c/freetype-2.1.9/objs/
smooth.o /cygdrive/c/freetype-2.1.9/objs/truetype.o /cygdrive/c/freetype-2.1.9/o
bjs/type1.o /cygdrive/c/freetype-2.1.9/objs/type42.o /cygdrive/c/freetype-2.1.9/
objs/winfnt.o
./builds/unix/libtool: line 1: lib: command not found
make: *** [/cygdrive/c/freetype-2.1.9/objs/libfreetype.la] Error 127
Poor lad!!! He copied this text and pasted it into notepad. Removing the newlines, he changed "lib" to "sh builds/unix/libtool --mode=finish" and pasted the command back into his command window, whereupon his command line simply gave him more greif. The poor lad was about to hang himself - no matter how much he tried to coax the library into installing, it just would not work! But the lad did not hang himself. The lad decided it was time to put this library into it's place. "Library!" he shouted. "Library! Hear me! I will put an end to thy wicked ways! Repent now or be manually compiled!" And the Library sat silent. "Library! This is your final warning! Surrender now, or feel the taste of my blade, GCC!!!" And the Library sat silent. The lad kept his trusty "GNU ld" up for defense, circling the library. It seemed to have all it's object files so far in one place... C:\freetype-2.1.9\objs\ . A quick feinting cd into the .libs subdirectory of that, followed by a quick stab to "cd ..", the lad thrust his mighty command: "gcc -shared *.o -o libfreetype.dll -shared -fPIC -mno-cygwin" (yes, the lad truely typed this first try) and lo and behold:
C:\freetype-2.1.9\objs>gcc -shared *.o -o libfreetype.dll -shared -fPIC -mno-cyg
win

C:\freetype-2.1.9\objs>
His code had compiled without error or even warning!!! Triumphant, he copied this new DLL into C:\cygwin\bin, edited his makefile for the new paths (which had previously been tangling with "C:\Program Files\GnuWin32" and it's children), and compiled. And lo and behold, instead of errors having nothing to do with this poor lad's code, there was output:
C:\eclipse\workspace\industry\>test
Everything seems to be running AOK
libindustry.gui.dll version: 0.01
showing that his trusty DLL's constructor,
void __attribute__((constructor)) industry_gui_dll_init( void )
{
	libindustry_gui_dll_version = "0.01";
	FT_Error error = FT_Init_FreeType( &library );
	if (error); //we should do something but we're lazy bastards
}
had indeed been called (as libindustry_gui_dll_version had no assignment besides there, as confirmation). The young lad, victorious, returned to his native homeland, GameDev.net, where he proclaimed his victory to the masses.
CloudNine
CloudNine
Good story! I'm glad it worked out well in the end.
MaulingMonkey
MaulingMonkey
Hehe, thanks. Originally I was just trying to get FTGL working, but then I realized FTGL sucked (C-style prefixes instead of namespaces, for one thing). Since most of the other libraries out there depended on FreeType (including FTGL), or don't have a method of getting per-character widths, or look ugly (glut builtin fonts), I really didn't have much choice. It took me a few hours (mainly googling), but hey, it's installed now, I think it works (I havn't actually tried viewing the results yet), and the nightmare is finally over.

Plus, the stores are open now (I pulled an all nighter for the hell of it) and I can now overdose on caffinee and breakfast. GLEE!!!
coldacid
coldacid
I particularily enjoy the believable combat. [grin]
Holy Sok
Holy Sok
nice one.. tho i think you need to leave off the prozac ;)
Ravuya
Ravuya
sudo apt-get install freetype2-devel

Yup, because Windows is totally the right kind of environment to get real work done in. :P

[Edited by - Ravuya on October 22, 2004 1:23:09 PM]
Ilici
Ilici
I wish i had your luck fixing the bug in the Radeon drivers for Fedora Core 3. (wtf, patch the kernel.. huh?)

Anyway, look at the link in my sig, you might find it interesting.
Mayrel
Mayrel
Aside: The king has decreed that cygwin sucks. By royal command, mingw/msys is the POSIX-like environment for Windows henceforth. Unless you need to use an X server.
George2
George2
Let me get this straight :

You're compiling in cygwin and you're passing the flag -mno-cygwin to the compiler ?
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon
coldacid
coldacid
-mno-cygwin makes it link against mingw libraries installed as part of Cygwin, if any. A good choice if you don't want to GPL your program, since normally Cygwin-built programs are linked against cygwin1.dll which is GPL'd.
MaulingMonkey
MaulingMonkey
Quote:
Original post by Ravuya
sudo apt-get install freetype2-devel

Yup, because Windows is totally the right kind of environment to get real work done in. :P


Allready did that on my Debian box. But I want a working windows environment too.

Quote:
Original post by George2
Let me get this straight :

You're compiling in cygwin and you're passing the flag -mno-cygwin to the compiler ?


No. I'm not using the cygwin shell, just the utilities.

Quote:
Original post by jdhardy
The GnuWin32 project comes in handy at times like this.

FreeType for Windows


See, I tried the GnuWin32 freetype DLL, and it didn't work. Bleh!!!

Quote:
Original post by Mayrel
Aside: The king has decreed that cygwin sucks. By royal command, mingw/msys is the POSIX-like environment for Windows henceforth. Unless you need to use an X server.


I plan on trying out the X server sometime very soon - I've been using WiredX (a java X server launched through browser) to play freeciv XD.

That aside, all I need is my C++ development tools. For the most part I access my debian box via ssh, ftp, pop3, smtp, http, and cvs. ftp/pop3/smtp arn't accessable from beyond the LAN, but I do plan on creating ssh tunnels for them someday (I am lazy as hell, and don't have a need for that right now. I use CVS because I have 2 machines I develop on a good bit, and then my linux server (hosting the CVS) which I plan to use as a compile farm once I get around to setting up cross-compilation tools. Once I move to California I'll be getting an apartment with enough room to set up my linux box completely (right now it's sort of hidden under stuff) at which point I'll use it for development, and as a TeamSpeak client as well (for when I play PlanetSide).
owl
owl
I didn't experienced any problems with it. I found it quite easy to install, compile and use, like many other libraries out there.
[size="2"]I like the Walrus best.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.