0

I need to compile a external source file from Visual Studio. I picked that from the developer command prompt:

cl /EHsc test.cpp

So I tried this:

system("cl /EHsc test.cpp");

But the command 'cl' doesn't exist in the normal cmd that is called by system()

Any suggestions how to use the compiler function anyway?

Simon Kraemer
  • 5,700
  • 1
  • 19
  • 49
Hexdec
  • 35
  • 6
  • 1
    `cl.exe` is part of Visual Studio. Have you checked your `PATH` variable? – Simon Kraemer Feb 22 '16 at 18:07
  • 3
    Why do you need to do this from a c++ program actually? – πάντα ῥεῖ Feb 22 '16 at 18:08
  • 2
    @πάνταῥεῖ Skynet? ;-) – Simon Kraemer Feb 22 '16 at 18:09
  • So if I understand you correctly, you want to compile a piece of cpp from a running piece of code in Visual Studio? If so, then cl will do that for you, but it will need to be on the system path and might need some environment variables set as well. Use the Visual Studio Administrator Command Prompt and then type 'set' to see what the environment is set to. – The Welder Feb 22 '16 at 18:13
  • @TheWelder Yes, I can see it. But I don't know what I should do next. Any idea? – Hexdec Feb 22 '16 at 18:43
  • Please see this [answer](http://stackoverflow.com/questions/4505362/cl-exe-not-finding-any-standard-include-file) – Andreas DM Feb 22 '16 at 18:50
  • @AndreasDM yes you are right, but I noticed that the Functions from cl.exe will be lost after running the compiled executable instead of the Visual Studio debugger. That means I think even If I would change the variables, I wouldn't get the result there. – Hexdec Feb 22 '16 at 19:05

1 Answers1

0

Now I did it myself and for those ones who are curious I did it by making a copy of the vcvars32.bat and added a few commands like this:

cd %~dp0%

cl /LD source.cpp /EHsc ;remember putting this part after the bat-file called all important commands

Now I just need to execute this file from c++ and here we go.

Hexdec
  • 35
  • 6