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

编译成功。

 

相关文章:

  • 2021-12-28
  • 2021-04-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2021-11-28
  • 2022-02-26
  • 2021-10-19
  • 2021-08-29
  • 2021-06-08
相关资源
相似解决方案