首页 > Windows开发 > 详细

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

时间:2019-05-05 13:01:59      阅读:264      评论:0      收藏:0      [点我收藏+]

一开始按照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

编译成功。

 

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

原文:https://www.cnblogs.com/schips/p/10812268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!