Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on October 15, 2009

Title: [C++] Compiling With CPP filename & co.
Post by: Clyde on October 15, 2009
Hiya,

As I make updates to versions of code in the same project / solution. I wondered rather than it keep overwritting the executable, is there a way to compile with a different filename, eg the one I am currently editting, for say "Fireworks 1-2.cpp" will generate "Fireworks 1-2.exe", and then if I do 1-3, that also makes "Fireworks 1-3.exe" ?

Also, whilst im on the keys, it's very confusing that I have multiple sets of Release And Debug folders within my projects. There's a set in the root directory, and then there's another set in "fireworks". is that normall?

Cheers and have a good one,
Clyde.
Title: Re: [C++] Compiling With CPP filename & co.
Post by: Jim on October 15, 2009
Quote
As I make updates to versions of code in the same project / solution. I wondered rather than it keep overwritting the executable, is there a way to compile with a different filename, eg the one I am currently editting, for say "Fireworks 1-2.cpp" will generate "Fireworks 1-2.exe", and then if I do 1-3, that also makes "Fireworks 1-3.exe"
There's no facility for doing that.  I'm not sure why you would want to.

Quote
it's very confusing that I have multiple sets of Release And Debug folders within my projects. There's a set in the root directory, and then there's another set in "fireworks". is that normall?
Not normal.  Some of them are left overs from your tinkering, there would usually only be one set.

Jim
Title: Re: [C++] Compiling With CPP filename & co.
Post by: rain_storm on October 15, 2009
you can specify it manuallly :
  project properties -> linker -> General -> Output File

By default this is set to "$(OutDir)\$(ProjectName).exe"
modfiy that to "$(OutDir)\YourNewExeName.exe"

It would be much quicker to just have your release folder open and rename the file itself. Than having to go through the options to rename it.

Title: Re: [C++] Compiling With CPP filename & co.
Post by: hellfire on October 15, 2009
Quote
is there a way to compile with a different filename, eg the one I am currently editting, for say "Fireworks 1-2.cpp" will generate "Fireworks 1-2.exe", and then if I do 1-3, that also makes "Fireworks 1-3.exe" ?
Well, that's what for example FB-IDE was doing and probably appears feasible to you for your C-coding, too.
But this makes sense for this specific Basic-IDE only because there's just one "main" source file and no associated linking process.

In C/C++ things work a bit differently. You usually have a lot (and for big projects that's thousands) of source-files that can be compiled independently. The benefit is when you change only a single file, the compiler can just recompile this single file and leave the rest untouched (saving a couple of minutes of rebuilding-time).
In a second process the linker assembles all the code that is spread across many .obj-files (and probably a couple of libs) to a single .exe.
The linker can't know that you want it to name the resulting executable just like one of the source-files, that's why you have to specify the name manually.

More generally I don't think it's a good idea to have different versions of source-files inside a single project, or even have version numbers within the filename.
The reason why there's a "project" at all is to let the compiler know what needs to be compiled and let the linker know what needs to stuffed into your exe.
If you've got things floating around that doesn't belong to any of these two then it's simply garbage.
When you've reached a state you want to preserve better make a copy.

Managing sources and settings is one of the main virtues of C++ programming.
Besides laziness, impatience and hubris of course.
Title: Re: [C++] Compiling With CPP filename & co.
Post by: Jim on October 15, 2009
Quote
Besides laziness, impatience and hubris of course.
Hey!  Those are some of my best qualities :P

Jim
Title: Re: [C++] Compiling With CPP filename & co.
Post by: Clyde on October 18, 2009
Thanks Hell Fire dude,

There's alot of habits I need to break; the simple solution if I need to is to rename the exe in windows explorer.

Not sure if im a hurbris.

Ah, before I go what would you tend to put into a header file, to clean up a tad a cpp file? And is that what they generally are, as some example projects I've seen look alot like a cpp. Sorry if this doesnt make alot of sense, hope you get the jist.

Thankyou,
Clyde.
Title: Re: [C++] Compiling With CPP filename & co.
Post by: Jim on October 18, 2009
Things that belong in include files are: constants, class definitions, enums, typedefs, structs, macros.  No code except inline methods in the classes.

If you want to get more tidy, make one include file for each class or concept (e.g. your sprite thing has a couple of related classes).  Make one cpp file for each class.  That way you'll find it easier to reuse classes in other projects.

Jim