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.