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
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
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
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: int main() { SetLINKVar(i); // This func will change the LINK Env Var . . . }
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 :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
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.
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/lib....vcprojectengine.vclinkertool.outputfile.aspx
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.
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
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
Icons are resources so you need to add the compiled resource file (.res, created from .rc) containing the icon to the link line.
I see. Pretty sure it's a .rc, could you please tell me how to include it? (resources.rc) Thanks in advance, Panarchy
You need to compile it first with a resource compiler (look for rc.exe). Adding it to the link line is as simple as concatenating the filename to the line, for example suppose you want to add FOO.RES to LINK A.O, you get LINK A.O FOO.RES.
Thanks, however I couldn't work it out. Please tell me how do include an icon within the .exe, via the Command-Line. Thanks in advance, Panarchy
So that needs compiling with the resource compiler to produce a .res file, then you can add the .res filename to the link line. The resource compiler used to be called rc.exe, but I can't find that under C:\Program Files\Microsoft Visual Studio 9.0. So MS must have renamed it to something else. I have an rc.exe in C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin but that seems like an odd place to keep it; anyway if you have that folder too then that might do the trick.
Nope, rc is still there. (all code tags are in order of how they are inputted) Code: [B]cl[/B] /clr "super.cpp" I've tried; Code: [B]rc[/B] super-resource.rc And that outputs an .res. Then using the full command; Code: [B]link[/B] "super.obj" /ASSEMBLYRESOURCE:super-resource.res /out:"Not Super.exe" Compiles the program, with the same size as when I compile the .exe using the GUI, HOWEVER, no icons. Please tell me how to get this to work. Thanks in advance, Panarchy
Can you specify the icon in the shortcut properties (Change Icon button)? If so then it's just a case of checking the resource compiler syntax to find out how to specify which icon is the default.