CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Join Date
    Nov 2007
    Posts
    92

    Question 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

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

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

    within your c++ code ? What do you mean by that ?

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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.
    Last edited by _Superman_; May 9th, 2009 at 10:02 AM.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  5. #5
    Join Date
    Nov 2007
    Posts
    92

    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



    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

  6. #6
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  7. #7
    Join Date
    Nov 2007
    Posts
    92

    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

  8. #8
    Join Date
    Nov 2007
    Posts
    92

    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

  9. #9
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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++.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  10. #10
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    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.

  11. #11
    Join Date
    Nov 2007
    Posts
    92

    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

  12. #12
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  13. #13
    Join Date
    Jul 2001
    Location
    Netherlands
    Posts
    751

    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.

  14. #14
    Join Date
    Nov 2007
    Posts
    92

    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?

  15. #15
    Join Date
    Nov 2007
    Posts
    92

    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.



    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured