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

Using Visual Studio 2008

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 2967 Views - Last Post: 03 June 2009 - 03:09 PM Rate Topic: -----

#1 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Post icon  Posted 09 May 2009 - 12:01 AM

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
Is This A Good Question/Topic? 0
  • +

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

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,066
  • Joined: 10-May 07

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

Posted 09 May 2009 - 12:05 AM

Use argv[0] :

#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("The name of the exe is : %s\n\n",argv[0]);
  return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 09 May 2009 - 12:14 AM

Thanks for replying.

Forgive my ignorance, the compiled output, the .exe, which part of the above code is it specified in?

Is it the %s\n\n or something else?

Please explain it to me.

Thanks in advance,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,066
  • Joined: 10-May 07

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

Posted 09 May 2009 - 12:16 AM

Check over this this Tutorial, it shows the usage of argc & argv.
Was This Post Helpful? 0
  • +
  • -

#5 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

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

Posted 09 May 2009 - 12:21 AM

Also printf() is a C throwback, in C++ the same line of code could be written:

cout << argv[0] << endl << endl;



the '%s' is a string, (argv[0] in this case)
and the two '\n's are newline characters
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,066
  • Joined: 10-May 07

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

Posted 09 May 2009 - 01:13 AM

View PostDoubleFission, on 9 May, 2009 - 01:21 AM, said:

Also printf() is a C throwback

Good catch. I have a bad habit providing C help for a C++ question.

Thanks for pointing out the difference.
Was This Post Helpful? 0
  • +
  • -

#7 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 10 May 2009 - 05:35 AM

Yeah, thanks.

PrintF was confusing me, well, I'll check the link now. So thanks to both of you!
Was This Post Helpful? 0
  • +
  • -

#8 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 10 May 2009 - 06:54 AM

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 http://msdn.microsof...y/8htcy933.aspx
Output File: http://msdn.microsof...outputfile.aspx
Was This Post Helpful? 0
  • +
  • -

#9 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

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

Posted 10 May 2009 - 07:00 AM

Are you trying to rename the file from whatever the default is?

So say you're always getting a.out.exe and you want program.exe
Was This Post Helpful? 0
  • +
  • -

#10 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 10 May 2009 - 07:23 AM

Exactly.

I will be making slight changes to the code, then recompiling the program more than 250 times, so the fastest way possible, with the smallest input is what I am looking for.

So a line or two of code that specifies the outfile, would be... bearable. (least # of KB added to the end is what I'm looking for)

Thanks in advance,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#11 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

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

Posted 10 May 2009 - 09:20 AM

By default VS generally names the .exe file after the project name, or at least that what it does for me in 2005.
Was This Post Helpful? 0
  • +
  • -

#12 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 10 May 2009 - 03:18 PM

Indeed, but there is another way to do it. See the links I mentioned before.

Thanks,

Panarchy
Was This Post Helpful? 0
  • +
  • -

#13 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 11 May 2009 - 07:15 PM

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
Was This Post Helpful? 0
  • +
  • -

#14 Panarchy  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 28-November 07

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

Posted 14 May 2009 - 03:07 AM

Please tell me how to get the icons to show in my .exe.

First, I'd like to be able to do this via the Visual Studio Command-Prompt.

Currently I'm using the following commands;
cl /clr "super.cpp"

rc	super-resource.rc

link  "super.obj"  /ASSEMBLYRESOURCE:super-resource.res /out:"Not Super.exe"


The above compiles the program, with the same size as when I compile the .exe using the GUI, HOWEVER, there are no icons.

Please tell me how to get this to work.

Thanks in advance,

Panarchy

This post has been edited by Panarchy: 14 May 2009 - 03:07 AM

Was This Post Helpful? 0
  • +
  • -

#15 Jubb  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 88
  • Joined: 06-May 09

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

Posted 14 May 2009 - 01:10 PM

That looks right, are you linking with the correct Resource file that has the icon inside?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3