Compiling a GTK app on Windows

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Compiling a GTK app on Windows

Postby '; DROP DATABASE;-- » Thu Feb 19, 2009 7:57 pm UTC

I've got a program that uses GTK, and one of the developers is using Windows and has no idea how to go about compiling it. As it turns out the GTK documentation is pretty unhelpful in this regard.

There's the matter of porting the makefile to Windows, finding replacements for date and pkg-config:
Spoiler:

Code: Select all

# ./configure --with-libraries=all --with-icu --prefix=/usr/lib

# make&&sudo make install



# Program info

PROGRAM = newmoon

OPTIONS =

SHARED = ./shared/

SHARED_OBJS = compat.o debugout.o mathx.o

SHARED_SRCS = $(SHARED)compat.cpp $(SHARED)debugout.c $(SHARED)mathx.cpp

OBJS = $(SHARED_OBJS) gui/cWindow.o gui/cDrawBox.o gui/cMainWindow.o gui/cPaletteWindow.o cGFXBuf.o cROMFile.o cSNESPointer.o cSMWObject.o cLevel.o main.o

OTHER_DEP =

LIBS = -L/usr/local/lib `pkg-config --libs gtk+-2.0`

#todo: if it's possible to get 'date' to output * or <<, we can avoid calling it 3 times

DAY = `date +%-d`

MONTH = `date +%-m`

YEAR = `date +%-y`

BUILD_INDEX = 0

BUILD_ID = "((BUILD_YEAR << 13) | (BUILD_MONTH << 9) | (BUILD_DAY << 4) | BUILD_INDEX)"



CMDLINE = $(PROGRAM)



LIBPATH = /usr/lib/

DELETE = rm -rf

#export PATH := $(MINGW)bin:$(PATH)

OS = LINUX



# etc

CXX = g++

CXXFLAGS = -O3 -Wall -I$(SHARED) -D$(OS) -DBUILD_DAY=$(DAY) -DBUILD_MONTH=$(MONTH) -DBUILD_YEAR=$(YEAR) -DBUILD_INDEX=$(BUILD_INDEX) -DBUILD_ID=$(BUILD_ID) -DGTK_MULTIHEAD_SAFE=1 `pkg-config --cflags gtk+-2.0`

LD = $(CXX)

LDFLAGS =

COMPILE = $(CXX) $(CXXFLAGS) -c



all: $(PROGRAM)

   @echo @@ START @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   @./$(CMDLINE)

   @echo @@ END @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

   

noexec: $(PROGRAM)

   

.PHONY : all noexec clean



$(PROGRAM): $(OBJS)

   $(LD) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) $(OPTIONS)

   

%.o: %.c $(OTHER_DEP)

   $(COMPILE) $(<) -o $(@)

   

$(SHARED_OBJS): $(SHARED_SRCS)

   $(COMPILE) $(^)

   

#this is stupidly complex for a simple recursive delete V_v

clean:

   $(DELETE) $(PROGRAM)

   find . -name "*.o" -exec rm -f {} \;

   find . -name "*.log" -exec rm -f {} \;

But even before that, I suppose he'd have to compile GTK itself too. Since I don't have a Windows box to play with I'm at a loss as to how to do that. Any ideas? (I'm tempted to say "install cygwin" or "switch to Linux", but it's an open-source app and the majority of users will be on Windows, so... <_<)

(and what the hell is with Failurefox duplicating line breaks in my pasted code?)
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

carletronicon
Posts: 9
Joined: Wed Sep 10, 2008 2:13 pm UTC

Re: Compiling a GTK app on Windows

Postby carletronicon » Thu Feb 19, 2009 11:15 pm UTC

I'd strongly recommend using msys / mingw ... I have successfully compiled multiple GTK applications (as well as gotten pyglade working) under that. The only problem I can think of off the top of my head was that the version of GTK that I had access to was either newer or older than the GTK for the linux target and some of the API had changed a bit... but since I had to do some #ifdef's for socket stuff (winsock is almost but not entirely like linux sockets), I wasn't too concerned.

I haven't used cygwin in a while, but I can vouch that you can then grab all the dll's that you need and include with the exe and the end user does not need to install any libraries.

Assuming you have all the libraries, you can then generally just do ./configure blah blah

User avatar
tetsujin
Posts: 426
Joined: Thu Nov 15, 2007 8:34 pm UTC
Location: Massachusetts
Contact:

Re: Compiling a GTK app on Windows

Postby tetsujin » Thu Feb 19, 2009 11:48 pm UTC

Personally I'd avoid Cygwin unless you really need it as a compatibility layer... It does funky stuff like emulating symlinks and mount points... This can make it slightly annoying to use a Cygwin program together with a non-Cygwin program (i.e., Cygwin thinks something is in /usr/bin - but actually it's in c:\cygwin\bin or something...). Basically, in pursuit of making it possible to compile and run just about any Unix program in Windows, Cygwin does more of a full layer on top of Windows, more extensive lies for its fictional Unix environment - while MinGW, as I understand it, attempts to provide the basic Unix API but without straying too far from the true underlying OS - better integration but maybe not the same level of compatibility with Unix source code...
---GEC
I want to create a truly new command-line shell for Unix.
Anybody want to place bets on whether I ever get any code written?

Karrion
Posts: 92
Joined: Fri Jun 22, 2007 12:14 am UTC
Location: Melbourne, AU

Re: Compiling a GTK app on Windows

Postby Karrion » Fri Feb 20, 2009 4:52 am UTC

See http://www.gtk.org/download-windows.html for binaries and source for windows versions of GTK+ and its dependencies.

User avatar
'; DROP DATABASE;--
Posts: 3284
Joined: Thu Nov 22, 2007 9:38 am UTC
Location: Midwest Alberta, where it's STILL snowy
Contact:

Re: Compiling a GTK app on Windows

Postby '; DROP DATABASE;-- » Sat Feb 21, 2009 7:24 pm UTC

Thanks, we've got it mostly worked out but we haven't found a proper replacement for the date command. This seems like it'd work, but is the output from %date% independent of locale?
poxic wrote:You suck. And simultaneously rock. I think you've invented a new state of being.

carletronicon
Posts: 9
Joined: Wed Sep 10, 2008 2:13 pm UTC

Re: Compiling a GTK app on Windows

Postby carletronicon » Sat Feb 28, 2009 12:05 am UTC

At the risk of beating a dead horse, msys has /bin/date which will do what you want... or did you go down an alternate non-msys route?


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 10 guests