cygwin gcc 编译windowsAPI 报错的一个解决方案

一开始按照linux的习惯去编译一个使用了windowsAPI的程序

结果提示:

$ i686-pc-cygwin-g++ screen_catch.c
screen_catch.c: In function ‘int main()’:
screen_catch.c:158:39: warning: ISO C++ forbids converting a string constant to ‘LPSTR {aka char*}’ [-Wwrite-strings]
     SaveBitmapToFile(hBmp,"c:\\11.bmp");
                                       ^
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x38): undefined reference to `_imp__CreateDCA@16'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x53): undefined reference to `_imp__GetDeviceCaps@8'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x6d): undefined reference to `_imp__GetDeviceCaps@8'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x83): undefined reference to `_imp__DeleteDC@4'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x101): undefined reference to `_imp__GetObjectA@12'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x215): undefined reference to `_imp__GetStockObject@4'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x251): undefined reference to `_imp__SelectPalette@12'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x264): undefined reference to `_imp__RealizePalette@4'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2aa): undefined reference to `_imp__GetDIBits@28'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2cf): undefined reference to `_imp__SelectPalette@12'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2df): undefined reference to `_imp__RealizePalette@4'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x48e): undefined reference to `_imp__CreateCompatibleDC@4'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x4c7): undefined reference to `_imp__CreateDIBSection@24'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x4e1): undefined reference to `_imp__SelectObject@8'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x52e): undefined reference to `_imp__BitBlt@36'
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x556): undefined reference to `_imp__DeleteDC@4'
collect2: error: ld returned 1 exit status

经过网上查找,发现是编译时没有链接到对应的库导致的。找到对应的库

g++ *.cpp  -l Gdi32

编译成功。

 

转载于:https://www.cnblogs.com/schips/p/10812268.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值