【问题标题】:libtool: error: can't build x86_64-w64-mingw32 shared library unless -no-undefined is specifiedlibtool:错误:除非指定了 -no-undefined,否则无法构建 x86_64-w64-mingw32 共享库
【发布时间】:2021-11-11 19:06:18
【问题描述】:

我正在尝试使用 MINGW64 和 Msys 在 windows10 上构建和安装 OpenFst 库,但在使用 make 构建时出现以下错误。我第一次使用这个命令:

 ./configure --enable-grm --enable-far --enable-ngram-fsts MAKE="mingw32-make"

此命令的某些检查结果生成否:

checking whether we are cross compiling... no
checking for sysroot... no
checking for a working dd... ./configure: line 7016: cmp: command not found
./configure: line 7016: cmp: command not found
checking for mt... no
checking if : is a manifest tool... no
checking for unistd.h... no
checking if gcc supports -fno-rtti -fno-exceptions... ./configure: line 8930: diff: command `not found`
checking whether to build static libraries... no

其他检查结果正常,是的。然后我使用了make命令:

mingw32-make

它适用于某些文件,然后因该错误而终止:

libtool:   error: can't build x86_64-w64-mingw32 shared library unless -no-undefined is 
specified

这是我第一次使用 MinGW 进行构建。所以,我不知道错误是什么意思,以及是否从负责它的配置中检查结果“否”。

【问题讨论】:

  • diff 命令有效吗?您可能需要安装它。此外,您应该使用make 而不是mingw32-make
  • @HolyBlackCat 不,差异不起作用。也使不工作,但“mingw32-make”做同样的工作。它们之间有什么区别?
  • make 是一个成熟的 Make(使用 MSYS2 的 Cygwin 分支)。 mingw32-make 是在没有 Cygwin 的情况下将 Make 移植到 Windows 的尝试,它使用 cmd 而不是 sh 作为外壳,并且由于大多数 makefile 不期望它,因此并非所有人都可以使用它。上次我尝试过,它也相当有问题。
  • “diff 不工作。也使不工作”你需要安装两者。
  • @HolyBlackCat 我安装了它们并使用 make 而不是 mingw32-make 但仍然出现错误。

标签: makefile c++17 mingw msys openfst


【解决方案1】:

这是正常的。

当仍有未解析的符号时,MinGW 不允许构建共享库 (DLL),因为在 Windows 上,从 DLL 引用的每个符号都必须指向存在的东西。在其他平台上,这并不总是必需的。

所以你应该在链接时将-Wl,-no-undefined传递给gcc

对于使用 autoconf 的 configure 的项目,如果它是足够新的 autoconf 版本,通常已经完成。否则,您可能需要将LDFLAGS="-Wl,-no-undefined" 添加到配置行。 如果这没有帮助,您可以尝试在configure 生成的libtool 文件中更改它。

所以特别是你可以在 MSYS/MSYS2 shell 中试试这个:

./configure LDFLAGS="-Wl,-no-undefined"

如果这不起作用,您也可以试试这个(在configure 命令之后和运行make 之前):

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

其他构建工具,如 cmake、meson 或 scons 已经知道如何构建 Windows DLL,无需特殊处理。

【讨论】:

  • 非常感谢,我会试试的
猜你喜欢
  • 1970-01-01
  • 2022-10-20
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
相关资源
最近更新 更多