问题
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")?>
To send the output of the test.exe file to the file.
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:
"The program can't start because cygwin1.dll is missing from your computer. Try reinstalling the program to fix this problem."
So, how can I make it so windows batch can execute cygwin-compiled files?
回答1:
You could do a few things:
- 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.
- 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.
- 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.
回答2:
"The program can't start because cygwin1.dll is missing from your computer. Try reinstalling the program to fix this problem."
Well the error message here is pretty clear. Executables compiled with Cygwin need cygwin1.dll to run. The easy way is to just copy that cygwin1.dll into the same locate as your executable so it can find it.
If you're not too crazy about that dependency you can try building your hello world with MinGW instead which doesn't have such dependencies.
回答3:
Copy cygwin1.dll into the directory containing test.exe
See The program can't start because cygwin1.dll is missing... in Eclipse CDT
来源:https://stackoverflow.com/questions/8888967/running-c-executables-compiled-in-cygwin-on-windows