-
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
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
within your c++ code ? What do you mean by that ?
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
You can't specify the name of the exe with your code. That's in the build options of the IDE.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Don't you think your question is a sort of chicken and egg problem.
To get the output name you have to build and run the EXE.
To build the EXE you have to give it a name.
If you mean you want to show the name of EXE from within the code you can either use the argv[0] parameter in the case of console application or in the case of Windows applications you can use GetCommandLine and CommandLineToArgvW functions.
-
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
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
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
You could probably write/record a macro that takes as input the name of the output desired. The could be put as a button on the toolbar.
On running the macro, it could set the output name in the Output File option in Project Properties -> Configuration Properties -> Linker.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Thanks, but the /out parameter can do it, if I can just work out how to use it.
Any ideas?
Panarchy
-
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
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
/out is a command line parameter of link.exe.
Refer to the Command Line option in Project Properties -> Configuration Properties -> Linker.
Also check out the Command Line option in Project Properties -> Configuration Properties -> C / C++.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
You could also copy/rename the file with Post build options from the settings dialog. I use VC++ 6 , maybe it's slightly elsewhere in dotnet.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
I'm using Visual Studio 2008 Professional, specifically the Visual C++ component.
Just trying to work out how to compile my program via the command-line, including the icon.
Any ideas?
Thanks in advance,
Panarchy
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
You will get the whole command line parameter for the CL.EXE compiler and the LINK.EXE linker from the project properties that I mentioned in my earlier post. Copy and paste that into the command window to execute it from command line.
This is of course for a single cpp file. For multiple files you will need to create a makefile.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
IN VC 2008 you can do the same as in VC6++
project settings => Build events => Post build-events:
REN $(TARGETPATH) newname.exe
or something like that.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Thanks, but how do I put that line directly into the .cpp file?
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
I got it to work by using the .res at the linking stage.
:D
So I've now successfully worked out how to compile, the program via command-prompt, specifying the name, and having the correct icon.
Thanks for all your help.
Now, any ideas on how I can do this within my C++ code?
Thanks in advance,
Panarchy
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Well, the idea is that .cpp is not a correct place for holding resource descriptions and build settings. That's why resource scripts, makefiles and/or project files exist.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Quote:
Originally Posted by
Panarchy
Thanks, but how do I put that line directly into the .cpp file?
You can't. Exe output is generated by the linker, and the linker never sees your source code.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Would it be possible, to use argv to specify the name of the .exe within my code?
Is that possible?
Thanks
Panarchy
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
No. Argv is used with the program runs. After the exe has already been created and named.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Ah.
Well, thinking outside the square, could I put some kind of copy/rename program/line to run as soon as program finishes compiling?
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
You do know that you can specify the name of the exe in your project settings, right? You can set up your project to do post-build actions though, if that's what you really want/need.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Okay, but how do I specify the post-build actions within the actual code?
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Hello Again!
I still haven't worked out how to do this :(.
Could someone please tell me how to set the name of the *.exe programmatically?
More info: http://msdn.microsoft.com/en-us/libr...utputfile.aspx
Please help me do this!
Thanks in advance,
Panarchy
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
Quote:
Originally Posted by
Panarchy
I wonder if you really read the "more info"? This article has nothing to do with the thread's topic. Because this is about how to write VisualStudio extension that can set the name of compiled exe.
Really more info:
Code:
// 503.cpp
#pragma comment(linker, "/out:mycool.exe")
int main()
{
return 0;
}
Code:
E:\Temp\503>cl 503.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
503.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:503.exe
503.obj
503.obj : warning LNK4070: /OUT:mycool.exe directive in .EXP differs from output filename '503.exe'; ignoring directive
...but
Code:
E:\Temp\503>cl 503.cpp /c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
503.cpp
E:\Temp\503>link 503.obj
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?
I got the same;
Code:
1>------ Build started: Project: VNC, Configuration: Release Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>VNC.cpp
1>Compiling resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>VNC.obj : warning LNK4070: /OUT:mycool.exe directive in .EXP differs from output filename 'C:\VNC\Release\VNC.exe'; ignoring directive
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Build log was saved at "file://c:\VNC\VNC\Release\BuildLog.htm"
1>VNC - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
-
Re: How-to specify the name of compiled output (*.exe) within C++ code?