GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Feb-2004, 10:56
Siphiro Siphiro is offline
New Member
 
Join Date: Feb 2004
Posts: 3
Siphiro is on a distinguished road
Question

compiling a program within another (C++)


I have a menu program and would like to compile another C++ program from within it. I have tried using the shellexecute command, but was unable to get it to work. That doesn't mean I was using it correctly though. I might also like to pass on variables from the menu program to the one that I am running. Is this possible?
  #2  
Old 05-Feb-2004, 11:07
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi Siphiro. Welcome to these forums.

Maybe you could provide a bit more detail about what you are trying to do. More particularly what environment and compiler you are trying to do this with.

It sounds like you are making a type of IDE where you could actually compile your code from within it.

Basically, it should be fairly simple to do depending upon which compiler that you want to call. I have provided a small snippet here that may help. Please note that this is basic c syntax, but you should be able to change it into c++ syntax if you wish.
CPP / C++ / C Code:
char* syscall = new char[MAX_SIZE];

strcpy(syscall,"gcc ");
strcat(syscall,filename);
strcat(syscall,flags);
strcat(syscall," -o sample");
system(syscall);

I believe the only header file that you should need is stdlib.h.

Anyway, if you could provide more details, we may be able to help you out some more.
  #3  
Old 06-Feb-2004, 10:58
Siphiro Siphiro is offline
New Member
 
Join Date: Feb 2004
Posts: 3
Siphiro is on a distinguished road
I am using Djgpp. Trying to run the "game" part of my program from my menu. I want them to be able to choose a saved game (already done) and then run the program. I have figured out how to get around passing variables from one to the other (just write them to a temp txt). So all I want is the command to run an exe from my code.
  #4  
Old 06-Feb-2004, 11:19
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Siphiro,

Sorry I misunderstood you. I thought you wanted to compile a program from a running program. However, the process is about the same. In fact it can be simply:

CPP / C++ / C Code:
system("c:\path\game.exe")

Note that you can pass parameters to this program as well, but your idea of passing data in a text file is probably easier. Note that the system call will wait until the called process is completed before continuing. If this is not the behavoir that you want then it may not work.
  #5  
Old 06-Feb-2004, 16:09
Siphiro Siphiro is offline
New Member
 
Join Date: Feb 2004
Posts: 3
Siphiro is on a distinguished road
what is the library that is in?
  #6  
Old 06-Feb-2004, 16:35
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by Siphiro
what is the library that is in?

stdlib.h

It is an ANSI C compliant call. You said you were using djgpp, I would be surprised if it wasn't in that compiler.
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loan Repayment program Tripod C Programming Language 18 10-Mar-2004 12:00
A question about the Amazon Affiliate Program JdS Advertising & Affiliates Forum 5 13-Jan-2004 18:00
how to run a program saintsnow75 C++ Forum 1 27-Nov-2003 12:06
error during program rjd72285 C++ Forum 0 11-Nov-2003 19:49
one program access another? dgoulston C++ Forum 1 07-Oct-2003 12:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.