Subscribe to GunnerInc's Blog        RSS Feed
-----

NASM and GTK+ on Windows kicked my ass!

Icon Leave Comment
I set out to see if I could write a simple Cross-OS program using NASM and GTK+ 2 on Linux and Windows. GTK is a cross OS GUI library, so it seemed it would be easy enough. Holy crap was I wrong!

On Linux, it is simple:
1. Build the GUI with GLADE and save the glade file.
2. Write Assembly code using NASM to load the glade file, show the window and all the other good stuff to interact with the GUI.
3. Using a makefile:
3a. Assemble with NASM.
3b. Link with gcc using
gcc -o cross_os cross_os.o `pkg-config --cflags --libs gtk+-2.0` -export-dynamic

I do all this from Geany, which is a nice editor.

Now for windows, I moved the directory from my Linux VM over to a Windows drive.
Then, I started a damn journey!
1. Download and install MinGW, GTK+ developer files and the runtime, Geany for Windows, and a few other things I forgot what they were.
2. added all the relevant directories to my PATH variable

Ok, now the fun really begins!
So, I loaded all the files up in Geany, changed a few parameters for the NASM and gcc commandline and hit Shift+F9 to run the makefile for shits and giggles, what happened? Errors up the wazoo! I am using Windows now, why was I expecting something different? Ok, so it turns out Windows does not like the backtick, ok, simple fix I am thinking, just run "pkg-config --cflags --libs gtk+-2.0" in a cmd window and copy that output to the gcc commandline. Lo and behold, more damn errors. Did a lot of searching on the net and tried many different fixes for this (mind you, none is for Assembly). Made a few more changes and still get errors. I am done, I spent more time then I would like to admit trying to get this to work and walk away from it for a while

Then I thought about it some, and thought:
Hmm, I really don't need to use gcc to link with! What does it do really? All it does is use its own entry point and gets the argv/argc and passes it to my main proc.

So how can I do this? I could do a few things and get the PEB for my program, but this is more of a hack than anything. Hmmm, msvcrt and the crt has __getmainargs which I will try. I will now try GoLink as my linker. What is cool about this linker is you don't need any libs, just pass it the dlls to look in for the used calls. Ok, now I make a file that contains all the dlls my program will use:
"freetype6.dll"
"intl.dll"
"libasprintf-0.dll"
"libatk-1.0-0.dll"
"libcairo-2.dll"
"libcairo-gobject-2.dll"
"libcairo-script-interpreter-2.dll"
"libexpat-1.dll"
"libfontconfig-1.dll"
"libgailutil-18.dll"
"libgcc_s_dw2-1.dll"
"libgdk-win32-2.0-0.dll"
"libgdk_pixbuf-2.0-0.dll"
"libgio-2.0-0.dll"
"libglib-2.0-0.dll"
"libgmodule-2.0-0.dll"
"libgobject-2.0-0.dll"
"libgthread-2.0-0.dll"
"libgtk-win32-2.0-0.dll"
"libpango-1.0-0.dll"
"libpangocairo-1.0-0.dll"
"libpangoft2-1.0-0.dll"
"libpangowin32-1.0-0.dll"
"libpng14-14.dll"
"zlib1.dll"
"msvcrt.dll"

Now I change the makefile to use GoLink instead of gcc:
GoLink.exe /entry _start cross_os.obj @imports.inc

OOOOH, no errors, it Assembles and Links WOOOOHOOOOO!!! Try running it, nope, nothing. Traced it to:
    push    NULL  
    push    szGladeFile
    push    eax 
    call    gtk_builder_add_from_file
    add     esp, 4 * 3 

Did some more internet searches on the error printed, nope, nadda, nothing works. For some reason, GTK on windows will not load the same glade file it does on Linux.

Now I like a good challenge, but the is beyond ridiculous! For now, I raise my white flag in defeat. Getting Assembly + GTK + Windows is too much of a challenge for me at the moment.

Hopefully at some point, I will get this to work and write a nice tutorial on it, but my ass is officially kicked at this point. Good battle GTK!

It is not like me to give up on anything so....

YES, SUCCESS!!!
Attached Image

I decided to remove the table and other controls from the glade file and start simple with a window and button, and as you can see, we have liftoff! It turns out, a widget (I am thinking the table widget) does not like windows.

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

August 2014

S M T W T F S
     12
3456789
10111213141516
171819202122 23
24252627282930
31      

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)

Categories