如何运行 C++在其他计算机上使用 PDCurses 的程序?
我最近开始在我正在开发的 C++ 游戏中使用 PDCurses。当我在自己的机器(Windows)上编译程序并运行 .exe 时,一切都按预期运行。
当我将该 .exe 带到另一台没有 PDCurses 的计算机上并尝试运行它时,我收到有关缺少 pdcurses.dll 文件的错误。
在网上做了一些研究后,我发现将 .dll 文件与 .exe 一起包含应该可以使其运行,但它对我不起作用。
这就是我使用 MinGW 编译程序的方式: g++ game.cpp -o game -lpdcurses
所以我的问题是,如何使这个程序在没有 PDCurses 设置的计算机上运行,并且,有没有办法通过将 .exe 与系统运行程序所需的任何其他文件结合起来来做到这一点?我还读到您可以进行某种静态链接,但到目前为止我还无法找到一种方法来做到这一点。
预先感谢您的帮助。
注意:如果重要的话,我会按照本教程设置 PDCurses: http://comptb .cects.com/1848-adding-pdcurses-to-mingw 不确定这是否是最好的方法,但我可以在我的计算机上编译和运行使用 pdcurses 的 C++ 代码。
抱歉没有发布确切的消息。它们是:
当我没有将 pdcurses.dll 文件与可执行文件一起包含时,我得到的第一个消息是:
程序无法启动,因为您的计算机中缺少 pdcurses.dll。尝试重新安装程序来解决此问题。
我在包含 pdcurses.dll 后得到的第二个问题是:
*程序无法启动,因为您的计算机缺少 libcc_s_dw2-1.dll。尝试重新安装程序来解决此问题。*
I've recently started using PDCurses in a C++ game I'm working on. When I compile the program on my own machine (windows) and run the .exe, everything works as it should.
When I take that .exe onto a different computer that doesn't have PDCurses and I try to run it, I get an error about a missing pdcurses.dll file.
After doing a bit of research online, I found out that including the .dll file along with the .exe should make it run but it didn't work for me.
This is how I compiled the program using MinGW: g++ game.cpp -o game -lpdcurses
So my question is, how do I make this program run on computers that don't have PDCurses setup, and also, is there a way to do this by combining the .exe with whatever additional file(s) the system needs to run the program? I've also read that you can do some sort of static linking but so far I've been unable to find a way to do this.
Thanks in advance for the help.
NOTE: In case it matters, I setup PDCurses following this tutorial: http://comptb.cects.com/1848-adding-pdcurses-to-mingw
Not sure if that was the best way to do it but I'm able to compile and run C++ code that uses pdcurses on my computer fine.
Sorry for not posting the exact messages. Here they are:
The first one I got when I didn't include the pdcurses.dll file along with the executable said :
The program can't start because pdcurses.dll is missing from your computer. Try reinstalling the program to fix this problem.
The second one I got after I included the pdcurses.dll:
*The program can't start because libcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要包含链接的所有动态库。小心许可,尽管 IIRC 并没有太多让 MinGW 困扰的地方。
如果您有 MinGW shell,应该有一个“ldd”命令。尝试在 game.exe 上运行它,它会告诉您运行程序需要哪些库。您需要将它们全部包含在 exe 中。
如果您想尝试消除依赖性噩梦,您可以在 gcc 链接命令中使用静态链接 (-static) 选项。如果您没有安装库的静态版本,您可能无法实际执行此操作。这还有其他影响 - 你的 exe 会更大,操作系统的共享页面代码将无法工作,因为它无法告诉你正在与其他应用程序共享哪些部分(DLL 代码)。实际上,您的应用程序将因此使用更多内存,尽管这可能微不足道。
You need to include all the dynamic libraries you linked with. Be careful of licensing, although IIRC there's not much that will bite you with MinGW.
There should be a 'ldd' command if you have the MinGW shell. Try running it on game.exe and it will tell you what libraries you need to run your program. You need to include them all with the exe.
If you want to try and remove the dependency nightmare you can use the static linking (-static) option to your gcc link command. You may not be able to actually do that if you don't have the static versions of your libraries installed. This has other implications - your exe will be bigger and the OS's shared shared page code will not work because it can't tell what parts (DLL code) you are sharing with other apps. In effect, your application will use more memory as a result, although it may be insignificant.
另一种选择是获取 PDCurses 的源代码并将其编译为静态库。这样您就不必陷入 DLL 地狱。
将其编译为 C 库而不是 C++ 库,这样就可以了。
Another option is to get the sources to PDCurses and compile it as a static library. That way you don't have to get involved in the DLL Hell.
Compile it as a C library instead of a C++ library and you should be good to go.