【问题标题】:Can't compile shared library in Mingw, compiler doesn't see system library无法在 Mingw 中编译共享库,编译器看不到系统库
【发布时间】:2021-05-22 10:53:21
【问题描述】:

我在尝试在 Windows 中使用 MinGW (msys2) 编译开源库时收到此警告

*** Warning: linker path does not have real file for library -lcrypt32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libcrypt32 and none of the candidates passed a file format test
*** using a file magic. Last file checked: C:/msys64/mingw32/i686-w64-mingw32/lib/libcrypt32.a

由于这个错误,我不能只编译静态共享库。

文件C:/msys64/mingw32/i686-w64-mingw32/lib/libcrypt32.a存在且正常链接在同一环境下的另一个库中

【问题讨论】:

    标签: linker mingw libtool


    【解决方案1】:

    警告消息由libtool 显示,以防找不到合适的链接候选库。就我而言,问题的根源是我的语言环境。安装的libtool 使用objdump 的输出来检查找到的候选是否是导入库并期望输出英文:

        if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
           $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|coff-arm|coff-arm64|coff-i386|coff-x86-64)' >/dev/null; then
    

    所以在制作库之前将语言设置为英语解决了我的问题:LANG=en_US.UTF-8 make

    【讨论】:

      【解决方案2】:

      您尝试构建的开源项目可能有一个旧的 configure 脚本,该脚本会生成一个 libtool,该脚本在 Windows(或 Windows 64 位,以防您是这样的情况下)无法正常工作建设)。

      运行autoreconf 是确保您拥有更新的configure 脚本的可能解决方案。一些来源还包括某种引导脚本。

      我见过其他情况,因为缺少链接器标志 -Wl,-no-undefined 而导致构建共享库 (DLL) 失败。这有时可以通过运行来解决:

      sed -i.bak -e "s/\(allow_undefined=\)yes/\1no/" libtool
      

      【讨论】:

      • 缺少-no-undefined 标志会在共享库编译期间导致错误,而不是警告
      • @AlexanderUshakov 链接共享对象时,如果没有该标志,链接器将失败,但 autoconf/make 将显示警告并仅构建静态库
      猜你喜欢
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 2021-05-20
      相关资源
      最近更新 更多