简体   繁体   English

在Cygwin / mingw上为Windows编译

[英]Compiling for windows on cygwin/mingw

So, I'm trying to compile a simple C example for the cairo graphics library in cygwin. 因此,我正在尝试为cygwin中的cairo图形库编译一个简单的C示例。 When compiling for cygwin, everything works as expected, but for windows it compiles, but doesn't work when trying to execute. 当为cygwin编译时,一切都按预期工作,但对于Windows,它可以编译,但在尝试执行时不起作用。

This is my makefile: 这是我的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? 尝试执行生成的.exe时,出现错误消息libcairo-2.dll丢失,但是由于它已链接,所以它不应该能够找到它吗? And is there any way to link to the needed dll's in a non-system folder? 并且有什么方法可以链接到非系统文件夹中的所需dll? I can't quite figure out how to do that. 我不太清楚该怎么做。

The import lib is located at 导入库位于

/usr/i686-w64-mingw32/sys-root/mingw/lib/libcairo.dll.a /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 WIN32LIBS =的/ usr / i686的-W64-的mingw32 / SYS-根/ MinGW的/ lib中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM