Bananicorn
Bananicorn

Reputation: 78

Compiling for windows on cygwin/mingw

So, I'm trying to compile a simple C example for the cairo graphics library in cygwin. When compiling for cygwin, everything works as expected, but for windows it compiles, but doesn't work when trying to execute.

This is my makefile:

CFLAGS= -lcairo

#WIN32HEADERS= /usr/i686-w64-mingw32/sys-root/mingw/include/cairo
WIN32HEADERS= /usr/i686-w64-mingw32/sys-root/mingw/include/cairo -I/usr/i686-w64-mingw32/sys-root/mingw/include/glib-2.0 -I/usr/i686-w64-mingw32/sys-root/minclude/glib-2.0 -I/usr/i686-w64-mingw32/sys-root/mlib/glib-2.0/include -I/usr/i686-w64-mingw32/sys-root/minclude/pixman-1 -I/usr/i686-w64-mingw32/sys-root/minclude/freetype2 -I/usr/i686-w64-mingw32/sys-root/minclude/libpng16 -I/usr/i686-w64-mingw32/sys-root/minclude/freetype2 -I/usr/i686-w64-mingw32/sys-root/minclude/libpng16

#WIN32LIBS= ./lib32
WIN32LIBS= ./usr/i686-w64-mingw32/sys-root/mingw/bin

#WIN64HEADERS= /usr/x86_64-w64-mingw32/sys-root/mingw/include/cairo
WIN64HEADERS= /usr/x86_64-w64-mingw32/sys-root/mingw/include/cairo -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/glib-2.0 -I/usr/x86_64-w64-mingw32/sys-root/minclude/glib-2.0 -I/usr/x86_64-w64-mingw32/sys-root/mlib/glib-2.0/include -I/usr/x86_64-w64-mingw32/sys-root/minclude/pixman-1 -I/usr/x86_64-w64-mingw32/sys-root/minclude/freetype2 -I/usr/x86_64-w64-mingw32/sys-root/minclude/libpng16 -I/usr/x86_64-w64-mingw32/sys-root/minclude/freetype2 -I/usr/x86_64-w64-mingw32/sys-root/minclude/libpng16

WIN64LIBS= ./lib64
#WIN64LIBS= ./usr/x86_64-w64-mingw64/sys-root/mingw/bin

CYGWINHEADERS= /usr/include/cairo
CYGWINLIBS= /usr/bin


all:
    i686-w64-mingw32-gcc kairo.c -o kairo_32.exe -I $(WIN32HEADERS) -L $(WIN32LIBS) $(CFLAGS)
    x86_64-w64-mingw32-gcc kairo.c -o kairo_64.exe -I $(WIN64HEADERS) -L $(WIN64LIBS) $(CFLAGS)
    gcc kairo.c -o kairo.o -I $(CYGWINHEADERS) -L $(CYGWINLIBS) $(CFLAGS)

#Build for Windows 32 Bit
win32:
    i686-w64-mingw32-gcc kairo.c -o kairo_32.exe -I $(WIN32HEADERS) -L $(WIN32LIBS) $(CFLAGS)

#Build for Windows 64 Bit
win64:
    x86_64-w64-mingw32-gcc kairo.c -o kairo_64.exe -I $(WIN64HEADERS) -L $(WIN64LIBS) $(CFLAGS)

#Build for Cygwin - maybe linux in general?
cygwin:
    gcc kairo.c -o kairo.o -I $(CYGWINHEADERS) -L $(CYGWINLIBS) $(CFLAGS)

#delete everything but the source files
clean:
    rm *.exe
    rm *.o

I've tried the commented out parts, as well as the currently active parts, but no luck. When trying to execute the resulting .exe, I get an error that libcairo-2.dll is missing, but shouldn't it be able to find it since it's linked? And is there any way to link to the needed dll's in a non-system folder? I can't quite figure out how to do that.

Upvotes: 1

Views: 991

Answers (1)

matzeri
matzeri

Reputation: 8496

The import lib is located at

/usr/i686-w64-mingw32/sys-root/mingw/lib/libcairo.dll.a

so you need to define

WIN32LIBS=/usr/i686-w64-mingw32/sys-root/mingw/lib

Upvotes: 3

Related Questions