Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   How-to specify the name of compiled output (*.exe) within C++ code? (http://www.go4expert.com/forums/specify-compiled-output-exe-cpp-code-t17436/)

Panarchy 9May2009 12:11

How-to specify the name of compiled output (*.exe) within C++ code?
 
Hello

How can I specify the name of the compiled output (the .exe) within my C++ code?

I'm using Visual Studio 2008.

Please tell me if this is possible, and if it is, how to do so.

Thanks in advance,

Panarchy

xpi0t0s 9May2009 16:19

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Normally you would specify it in the project file. Why do you want to specify it in the code?

What you could do if you want to set the executable name at runtime is to check argv[0], then if it's not correct you could copy that file to the filename you want, then launch that new executable, exit, and in the new executable check if this has just happened and delete the old executable.

Anyway there doesn't seem to be anything here that suggests /OUT can be overridden by anything in the source:
http://msdn.microsoft.com/en-us/library/8htcy933.aspx

Panarchy 10May2009 18:11

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Yes, I could very easily, manually, rename my .exe's to what I want them to be.

However, since I am going to be recompiling this program, with slightly different content, over 250 times, I'd like to be able to create each *.exe in the fastest way possible.

This means specifying everything in the code, then pressing the hotkey function for compiling.

Nothing more should be done, for maximum speed.

I can test 'em at some point as well... but for maximum speed, it'd be best to do it with the aforementioned method.

Please tell me if argv can do this, and if it can, how I can make it do so.

Thanks in advance,

Panarchy

EDIT: Those MSDN links seem alright, currently reading the documentation. Will tell you how it goes

SaswatPadhi 10May2009 18:57

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
It's a tough task, I think.

Take a look at this : http://msdn.microsoft.com/en-us/library/6y6t9esh.aspx
So, the linker uses the options and arguments defined in the "LINK" environment variable.

So, I think this will work (not tested though):
(1) Create a system environment variable called "LINK" with value "/OUT <default_filename>".
(2) Inside your C++ code, change the LINK variable to "/OUT <default_filename_i>", where "i" is an index.
(3) Compile, I think the LINK variable will take care of the rest :wink:

Code: c++

int main()
{
       SetLINKVar(i);    // This func will change the LINK Env Var
       .
       .
       .
}


Panarchy 10May2009 19:13

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
I was just thinking, I could have 1 command prompt window open, and 1 Visual Studio main.cpp (or equivalent) open.

I could then make the changes to the code, Alt-Tab to the command-prompt window, then put in what I want the .exe to be via the /out parameter.

Advantages;
- No extra code needs to be added
- So the size of my program won't enlarge

:D

Problem solved!

Disadvantages;
- Have to do an Alt-Tab :rolleyes:
- Command-Prompt sucks, as I need to right-click, Paste :crazy:

Though I still would like to know if this can be done programmatically, it is no longer a priority.

If you know how I can get this to be done programmatically, please tell me.

Thanks in advance,

Panarchy

Links:
/OUT
Output File

xpi0t0s 11May2009 04:16

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Sounds like a job for a script file. Just write a batch file, or a C program to generate a batch file, containing commands like
Code:

cl prog.c define=prog1 /out:prog1.exe
cl prog.c define=prog2 /out:prog2.exe

(nb: I'm not sure what the command line syntax for defines is) then in the code for prog1.exe you use a #ifdef prog1/#endif block etc.

Or you could make it more complex, for each variation in code you can have
Code:

#ifdef variation1a
// code
#else if variation1b
// code
#endif

then in the script file:
Code:

cl prog.c define=variation1a define=variation2a define=variation 3a /out:prog1.exe
cl prog.c define=variation1a define=variation2b /out:prog2.exe

etc. Basically you can make it as complicated as you want.

Panarchy 11May2009 07:59

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Thanks.

However, is there a way to get the Output File thing working?

Please tell me if you know a way.

Thanks in advance,

Panarchy

PS: Link;
http://msdn.microsoft.com/en-us/libr...utputfile.aspx

xpi0t0s 11May2009 12:09

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Yes I came across that but I didn't know if you were linking with the .Net library at all. A "String^" (note the circumflex) is a pointer to a managed String object so this is not applicable if you're not using .Net at all.

Panarchy 12May2009 02:25

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Ahaha... no wonder I'm confused. Well thanks anyways.

If you, or anyone else thinks of a way I can get this to work, please don't hesitate to post your ideas.

Thanks in advance,

Panarchy

Panarchy 12May2009 07:27

Re: How-to specify the name of compiled output (*.exe) within C++ code?
 
Hi

I've worked it out, first I need to do a;

cl /clr "test.cpp"

Then

Link "Test.obj" /out:"testing.exe"

There is one problem with this though, that is it doesn't give me an icon.

Doing it manually using the GUI, it does include an icon.

So any ideas on how I can embed the icon via the CLI?

Thanks,

Panarchy


All times are GMT +5.5. The time now is 01:52.