在Windows上运行在Cygwin中编译的C ++可执行文件 [英] Running C++ executables compiled in Cygwin on Windows

查看:69
本文介绍了在Windows上运行在Cygwin中编译的C ++可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想法
我已经在Cygwin上使用G ++编译了一个C ++ exe,我希望能够通过PHP将该exe的输出获取到HTML中.也就是说,假设我有一个C ++可执行文件"test.exe",其输出为"Hello,World!".运行时.那么从逻辑上讲,我应该能够做到

The Idea
I've compiled a C++ exe using G++ on Cygwin, and I want to be able to get the output of that exe into my HTML via PHP. That is, let's say I have a C++ executable "test.exe" which outputs "Hello, World!" when run. Then logically, I should be able to do

<?=exec("./test.exe")?>

要将test.exe文件的输出发送到该文件.

To send the output of the test.exe file to the file.

问题
我正在Win7的本地WAMP服务器上对此进行测试.显然,Win7 WAMP上的 exec system 调用是通过Windows命令提示符进行的,这意味着它正在运行批处理而不是bash.由于某些原因,批处理不喜欢Cygwin编译的可执行文件,并给出错误:

The Issue
I'm testing this on a local WAMP server on Win7. Apparently, exec and system calls on Win7 WAMP go through the Windows command prompt, meaning it's running batch instead of bash. For some reason, batch doesn't like Cygwin-compiled executables, giving the error:

该程序无法启动,因为您的cygwin1.dll丢失电脑.尝试重新安装该程序以解决此问题."

"The program can't start because cygwin1.dll is missing from your computer. Try reinstalling the program to fix this problem."

那么,如何使Windows批处理能够执行cygwin编译的文件?

So, how can I make it so windows batch can execute cygwin-compiled files?

推荐答案

您可以做一些事情:

  1. 您可以使用Visual Studio编译应用程序(我相信Microsoft提供了免费版本... Visual Studio Express ).这是我个人会选择的路线.您无需依赖cygwin DLL(除非您要在cygwin安装的某些部分中进行编译),并且您的可执行文件将在Windows系统上具有更大的可移植性.
  2. 您可以将 cygwin1.dll 的位置放入系统PATH环境变量中.这具有使用cygwin生成的将来的可执行文件成功运行的优点,但是具有的缺点是,如果您要分发应用程序,其他用户将无法立即运行它.
  3. 您可以将cygwin安装目录的/bin目录中的 cygwin1.dll 复制到与可执行文件相同的文件夹中.这是可移植的(在Windows系统上……在某种程度上),但是具有它可能违反Cygwin许可证的缺点(我不确定还没有阅读该许可证).我只建议将此路线用于测试目的.
  1. You could compile your application with Visual Studio (I believe Microsoft provides a free version ... Visual Studio Express). This is the route I would personally take. You won't need to rely on the cygwin DLL's (unless you're compiling in some part of the cygwin install), and your executable would be much more portable across Windows systems.
  2. You could place the location of the cygwin1.dll into your system PATH environment variable. This has the advantage of future executables built using cygwin running successfully, but has the disadvantage that should you want to distribute your application, other users wouldn't be able to run it out of the box.
  3. You could copy cygwin1.dll from the /bin directory of your cygwin installation into the same folder as your executable. This is portable (among Windows systems ... to some extent), but has the disadvantage that it might violate the Cygwin license (not having read the license, I'm not sure). I would only recommend this route for testing purposes.

这篇关于在Windows上运行在Cygwin中编译的C ++可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆