Skip to main content
gamedev.net
🔒 Locked

compiling generated code

Started by dathui Apr 9, 2006 at 6:05 PM 1 replies 700+ views
Original Post
dathui
dathui
What would be the easiest way to generate executable files from a file? say i got my generator.exe and depending on input want to compile either

#include <iostream>
int main() { std::cout <<"Foo" <<endl; }
or

#include <iostream>
int main() { std::cout <<"Bar" <<endl; }
One way would be to just generate a source-file and then using cl.exe and link.exe from the visual toolkit, but i wonder if there's another way.
reality is only an option
smart_idiot
smart_idiot
I don't know the proper way to invoke cl from the comand line, but with GCC. . .

#include <iostream>int main() { std::cout << BAZ << std::endl; }


g++ myfile.cpp -DBAZ=\"Foo\" -o myprogram

Alternately,

#include <iostream>int main(){  #if version == 1    std::cout << "Foo" << std::endl;  #elif version == 2    std::cout << "Bar" << std::endl;  #else    #error version isn't 1 or 2  #endif}


g++ myfile.cpp -Dversion=1 -o myprogram

You want a better variable name than version though, that's likely to be used in a program, wouldn't want every instance of it to get replaced with a 1, would you?

There should be something similar with your compiler. Read thy documentation.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
dathui
dathui
yea that's what i meant with using cl.exe and link.exe, it's the windows version of what you said. What i'm wondering is if there's another way.
reality is only an option

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.