1. 程式人生 > >cygwin gcc 編譯windowsAPI 報錯的一個解決方案

cygwin gcc 編譯windowsAPI 報錯的一個解決方案

沒有 select cti bit constant 提示 section .text sta

一開始按照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 `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x53): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x6d): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x83): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x101): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x215): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x251): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x264): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2aa): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2cf): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x2df): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x48e): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x4c7): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x4e1): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x52e): undefined reference to `[email protected]‘
/tmp/cc2yXn3P.o:screen_catch.c:(.text+0x556): undefined reference to `[email protected]‘
collect2: error: ld returned 1 exit status

經過網上查找,發現是編譯時沒有鏈接到對應的庫導致的。找到對應的庫

g++ *.cpp  -l Gdi32

編譯成功。

cygwin gcc 編譯windowsAPI 報錯的一個解決方案