views:

374

answers:

3

Can anyone help me with the compilation of C++ code in PHP on the Windows platform? I am using Microsoft Visual C++ 6.0.

I have tried the following options which I knew, but none of them work:

system('test.c') 
exec('test.c')

The file 'test.c' has been placed in my php/www/ folder.

I need to first compile the code, which makes test.exe and then using exec( ) I need to run the exe file.


Edit:

In this code "test.c", I am reading from a file "data.txt". The contents of data.txt is changed every 5 seconds. That's why first I need to compile in PHP and then run the new exe file.

+1  A: 

You need to call the compiler (cl.exe) and linker explicitly (See compiler reference) or use makefiles (g++ reference, but shows the point)

Dario
A: 

I am assuming you want to invoke your compiler from a php script?

If that's the case, you'll first have to invoke the compiler itself - not just pass the source code's filename to system. In the case of MSVC++, you will want to look for "cl.exe".

Also, if the corresponding path isn't set in your environment, you will need to use the full path.

Make sure to first understand, how to invoke cl.exe manually, from a command prompt. Once you understand that, you can try to invoke it from a php script.

However, you need to realize that there are additional factors to consider, such as for example the time required to compile a file vs. the time allowed for a php script to execute before timing out.

I think, you may need to provide us with additional information on what exactly you want to do, and why you want to do it.

none
+3  A: 

Do a .bat file that:

  • runs the vcvars32.bat file that comes with Visual Studio
  • runs "cl.exe yourprogram.c"

Then launch that .bat file from PHP. (dunno how you would do that btw)

friol
Thankxxx :) Problem has been solved.
@friol: eval() does it
Andrew Sledge