Linux下使用mingw32交叉编译SFML程序到Windows - 缺失dll文件

8
我正在以下方式编译我的C++项目:

/usr/bin/i686-w64-mingw32-g++ -g -std=c++0x -Wall -I /home/bluszcz/dev/win64/SFML-2.1/include -L /home/bluszcz/dev/win64/SFML-2.1/lib -static-libgcc -static-libstdc++ -static -O4 -c src/game.cpp -o src/game.a -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

然而,当我尝试运行我的exe文件时,会出现缺少DLL文件的错误:
bluszcz@zendo ~/dev/win32/builds/magicwizard $ wine mw.exe 
err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-system-2.dll") not found
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libwinpthread-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-system-2.dll") not found
err:module:import_dll Library sfml-system-2.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found
err:module:import_dll Library libgcc_s_dw2-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found
err:module:import_dll Library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libwinpthread-1.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\libstdc++-6.dll") not found
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\bluszcz\\dev\\win32\\builds\\magicwizard\\sfml-audio-2.dll") not found

我已经使用了静态选项进行编译 - 为什么还会提示需要 libgcc_s_dw2-1.dll 这样的文件呢?此外,我将一些文件复制到了该位置,但应用程序仍然无法看到它们。
bluszcz@zendo ~/dev/win32/builds/magicwizard $ ls *dll
libsndfile-1.dll  sfml-audio-2.dll     sfml-graphics-d-2.dll  sfml-system-2.dll    sfml-window-d-2.dll
libstdc++-6.dll   sfml-audio-d-2.dll   sfml-network-2.dll     sfml-system-d-2.dll
openal32.dll      sfml-graphics-2.dll  sfml-network-d-2.dll   sfml-window-2.dll
bluszcz@zendo ~/dev/win32/builds/magicwizard $

还有一些文件,比如libgcc_s_dw2-1.dll在我的文件系统中根本不存在...

总结一下:

  1. 为什么我的应用程序看不到缺失的文件?
  2. 如何使用mingw32进行静态编译?
  3. 如何获取缺失的文件?

我使用这个版本的sfml库进行编译:http://www.sfml-dev.org/download/sfml/2.1/SFML-2.1-windows-gcc-4.7-mingw-32bits.zip


您可以设置 WINEPATH 指向包含 DLL 文件的文件夹。例如:WINEPATH=/usr/local/x86_64-w64-mingw32/bin/;/usr/lib/gcc/x86_64-w64-mingw32/10-win32/ - Daniel Stevens
4个回答

1
缺失的dll文件可以在使用wine运行程序之前,将其添加到WINEPATH中,例如:
export WINEPATH="/usr/x86_64-w64-mingw32/lib;/usr/lib/gcc/x86_64-w64-mingw32/7.3-posix"

请注意,根据您使用的mingw版本,路径可能略有不同。


0

可能是因为你的应用程序已经配置好了,所以它没有看到这些文件,你不需要在命令中添加像-static这样的标签。

对于编译静态库,你必须添加-s,例如-lsfml-window-s -lsfml-system-s

libgcc_s_dw2-1.dll就在最新的MinGW releasesbin文件夹里。

如果有缺少的dll文件,那么可能存在版本不兼容的问题。


0
在我的 Fedora 26 上安装了 mingw64-gccmingw64-gcc-g++ 后:
[leo@pc]$ locate libgcc_s_seh-1.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll
[leo@pc]$ locate libstdc++-6.dll
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/libstdc++-6.dll
[leo@pc]$ 

如果我复制dll文件并使用生成的a.out.exe运行wine,它可以正常工作。


0

仅回答三个问题中的最后一个:

关于标准库,我成功地将它们从mingw文件夹中复制了出来:

cp /usr/lib/gcc/i686-w64-mingw32/5.3-win32/libstdc++-6.dll ./

然而,当我根据我的构建从错误的目录复制(例如/usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/libstdc++-6.dll)时,尽管具有完全相同名称的文件在此处,但我仍然遇到了相同的错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接