zoukankan      html  css  js  c++  java
  • 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

    编译成功。

  • 相关阅读:
    Android四:sqllite
    Android三-AsyncTask
    Android二-.9.png
    【SQL Server】系统学习之三:逻辑查询处理阶段-六段式
    Android一 流
    【SQL Server】系统学习之二:索引优化
    【SQL Server】系统学习之一:表表达式
    【wp之二 页面布局】
    Asp.net三种事务处理
    vs2008 启动IE浏览器 出现DW20.exe占用大量cpu 服务器iis 异常调试
  • 原文地址:https://www.cnblogs.com/schips/p/10812268.html
Copyright © 2011-2022 走看看