Hello,

This is something that I need to do in my program, that's a little though for me to define in a few words for Google, I couldn't find any useful results.

The thing is this, I have a program that creates a bunch of code files(.cpp and .h, in native format), that are ready and valid and just need to be compiled together, of course I can just take them after being created and putting them in a project in VS and compiling manually, but I'm looking for a faster method, a way to compile them from within the program that created them, peraphs calling the compiler from within it to do the work.

The way I tried to do that was use the File::Copy() method, to copy the cmd and vcvarsall.bat(I'm using VS to compile) to the same folder as the files that I want to compile, and then tried using Process:: Start(), but that didn't quite work, I couldn't find a way to make it start vcvarsall.bat. And I'm not even sure that this is at all what I SHOULD be doing.

Any input from more experienced programmers for this please?

Edited 5 Years Ago by KazenoZ: n/a

Can you do it? Yes, its just a matter of building a string or strings containing the the compiler name and proper switches plus the files in question and then calling system(created_string).

Edited 5 Years Ago by gerard4143: n/a

Could you possibly demonstrate this line of thought? I'm not quite sure what to do with this info...

An alternative method is to write a shell script that first runs your original programme, and then when that's finished runs the compiler on the created source code.

I do that with a bash script as follows:

#!/bin/bash
make intermediate
./intermediate
make unitTester
rm intermediate
mkdir unitTesterDir
mv unitTester unitTesterDir/unitTester
make clean

The programme intermediate is made, and then run, and then unitTester is created out of files that the programme intermediate created.

This method requires that you know how to compile from the command line, which is what those make commands are doing for me. I seem to recall that windows does have some kind of shell scripting capability. BAT files, was it? Or was there some new (better) shell released in the last few years?

Can you do it? Yes, its just a matter of building a string or strings containing the the compiler name and proper switches plus the files in question and then calling system(created_string).

Following on the grounds of gerard.

If u already have a batch file that does all the work for you. And are sure that the files will be compiled within the windows environment only,

I guess you could use the system() present in <cstdlib>.

All you have to do is

system("bat_file_name");

yeah i think a shell script would do the job. Hamilton C shell was developed for windows. i cant be more help in that respect - ive never written a shell script.

What about system()? cant you use that to run your compiler?

Following on the grounds of gerard.

If u already have a batch file that does all the work for you. And are sure that the files will be compiled within the windows environment only,

I guess you could use the system() present in <cstdlib>.

All you have to do is

system("bat_file_name");

This seems like a good soltuion, but I have 2 question about that;
1 being how can I attach libraries to the compilation if I do that?
And 2, considering that the bat will be located at the Visual Studio folder, how do I get it to change location to my current directory and compile from there, through my current program, without having to type anything at run-time?

Edited 5 Years Ago by KazenoZ: n/a

In reference to question 2

Quoting from your previous post


The way I tried to do that was use the File::Copy() method, to copy the cmd and vcvarsall.bat(I'm using VS to compile) to the same folder as the files that I want to compile

Maybe you could copy the bat file into the current directory and then run it with the system call

------------------------
What libraries do you wish to attach?

In reference to question 2

Quoting from your previous post


Maybe you could copy the bat file into the current directory and then run it with the system call

------------------------
What libraries do you wish to attach?

Well, if I do that... well, I don't know, won't it be just about the same as a Process::Start(), just without the arguments I could enter with the latter? Either way I don't really understand how to use it like that...

And as for the libraries, I need to attach the various SDL libraries, anything about that?

Actually, let me rephrase my wonderings...

My main goal is to create a game engine that suits my needs, this part of the code I need is what turns the code I generated from the editor program, into the actual executable... Think, RPG Maker, Unity, UDK and the like, how do they do it? What would be the simplest method?

It sounds like you are looking for an interpreted language which can interact with you c++ code. If that is the case, then look at languages like lua, e.g. http://www.lua.org. Used with swig it makes a really quick interface, http://www.swig.org

There are others, but I found these two worked well for me. I will point out that python is used a lot but I haven't had much experience using it.

What you might be looking up in google is "C++ interface interpreted". That gets you stuff about interfaces to a host of languages e.g. R, SQL, perl etc.

Maybe this helps.

I'm not sure how that would really help me? My program is already made in C++ as a form application, all I need is a way to compile the native C++ code it produces when run, be it from within the program itself, or an external program, just something that would work.

This article has been dead for over six months. Start a new discussion instead.