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
|
Mentor
|
![]() |
| 9May2009,16:19 | #2 |
|
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 |
|
Contributor
|
|
| 10May2009,18:11 | #3 |
|
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 Last edited by Panarchy; 10May2009 at 18:19.. |
|
~ Б0ЯИ Τ0 С0δЭ ~
|
![]() |
| 10May2009,18:57 | #4 |
|
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 ![]() Code: c++
|
|
Contributor
|
|
| 10May2009,19:13 | #5 |
|
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 ![]() Problem solved! Disadvantages; - Have to do an Alt-Tab ![]() - Command-Prompt sucks, as I need to right-click, Paste ![]() 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 |
|
Mentor
|
![]() |
| 11May2009,04:16 | #6 |
|
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 Or you could make it more complex, for each variation in code you can have Code:
#ifdef variation1a // code #else if variation1b // code #endif Code:
cl prog.c define=variation1a define=variation2a define=variation 3a /out:prog1.exe cl prog.c define=variation1a define=variation2b /out:prog2.exe |
|
Contributor
|
|
| 11May2009,07:59 | #7 |
|
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 |
|
Mentor
|
![]() |
| 11May2009,12:09 | #8 |
|
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.
|
|
Contributor
|
|
| 12May2009,02:25 | #9 |
|
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 |
|
Contributor
|
|
| 12May2009,07:27 | #10 |
|
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 |






