Depends on the operating system. MS-Windows I'd say its vc++ 2010. *nix it would be either g++ or Code::Blocks. For portability between the two operating systems (and I think MAC too) it would have to be Code::Blocks.

Do you mean compiler or IDE?

In many people's mind they are one and the same. In some cases they are while in others they are not. Code::Blocks is an IDE, not a compiler and AFAIK it can be configured to work with most modern compilers.

Context really matters here, best C++ compiler related to which view.
like compiler which builds fast, compiler which helps code to execute fast and etc..
So the viewpoint really does matter.

Comments

Here's my opinion on it (compilers, not IDE or build-systems):

Portability: GCC (GNU Compiler Collection)
Compilation Speed: BCB (Borland C++ Builder)
Code Optimization: ICC (Intel Compiler Collection)
Usefulness of compilation warnings and errors: GCC
Debugging capabilities: MSVC 2010 (Microsoft Visual C++ 2010)
Strict standard compliance: Comeau and ICC (using the EDG front-end)

Overall, GCC is a great option and MSVC is also pretty good, expecially considering both are free. The BCB compiler is also very good but a bit isoteric (has the same back-end as the Delphi compiler, which has some visible impacts in the form of some non-standard things, but it also gives it a much better compilation speed). As for code optimization, nothing beats the Intel compilers on Intel systems, but GCC is coming close to catching up to ICC, while MSVC is still shamefully lagging behind by a significant margin (and I don't know the current status of BCB, but earlier versions used to beat both GCC and MSVC like a rented mule while almost matching up to ICC, but that is probably not the case anymore because ICC, GCC and MSVC have improved a lot since then). GCC has also improved (4.5+) a lot when it comes to compilation times (my code-base used to take about 45min to compile entirely in pre-4.5 versions of GCC, now it takes about 15min with 4.6.2 version).

Comments
useful compilation

Here's my opinion on it (compilers, not IDE or build-systems):

Portability: GCC (GNU Compiler Collection)
Compilation Speed: BCB (Borland C++ Builder)
Code Optimization: ICC (Intel Compiler Collection)
Usefulness of compilation warnings and errors: GCC
Debugging capabilities: MSVC 2010 (Microsoft Visual C++ 2010)
Strict standard compliance: Comeau and ICC (using the EDG front-end)

Overall, GCC is a great option and MSVC is also pretty good, expecially considering both are free. The BCB compiler is also very good but a bit isoteric (has the same back-end as the Delphi compiler, which has some visible impacts in the form of some non-standard things, but it also gives it a much better compilation speed). As for code optimization, nothing beats the Intel compilers on Intel systems, but GCC is coming close to catching up to ICC, while MSVC is still shamefully lagging behind by a significant margin (and I don't know the current status of BCB, but earlier versions used to beat both GCC and MSVC like a rented mule while almost matching up to ICC, but that is probably not the case anymore because ICC, GCC and MSVC have improved a lot since then). GCC has also improved (4.5+) a lot when it comes to compilation times (my code-base used to take about 45min to compile entirely in pre-4.5 versions of GCC, now it takes about 15min with 4.6.2 version).

Since you recommend GCC/MSVC, I would say Go for CodeLite/CodeBlocks IDE. They both allow either MSVC/GCC compiler plus they both bundle GCC as a choice.
For long now I use CodeLite and I'm satisfied!

I wouldn't go with the microsoft products because they are too resource heavy, and are too complex for simple things.

I wouldn't go with the microsoft products because they are too resource heavy, and are too complex for simple things.

That's probably true for students, but not for real-world huge projects. VC++ 2010 beats the hell out of all other competitors when it comes to large-scale MS-Windows programs which contain hundreds of *.c, *.cpp and *.h files and multiple projects that depend on each other all of which are developed by a large development staff (20+programmers).

That's probably true for students, but not for real-world huge projects. VC++ 2010 beats the hell out of all other competitors when it comes to large-scale MS-Windows programs which contain hundreds of *.c, *.cpp and *.h files and multiple projects that depend on each other all of which are developed by a large development staff (20+programmers).

It boils down to managers and CTOs. If they say this or that you either obey or find another job. But I always avoid MSVC, but I think It have improved alot since I last tried (MSVC 2005). I think main reason is I'm content with my Current IDE

I have to go with MSVC++ 2010. I really love the debugger and if you mistype a variable name it will get a red underline letting you know it doesn't know what it is.

That's probably true for students, but not for real-world huge projects. VC++ 2010 beats the hell out of all other competitors when it comes to large-scale MS-Windows programs which contain hundreds of *.c, *.cpp and *.h files and multiple projects that depend on each other all of which are developed by a large development staff (20+programmers).

I'm sorry If I understood incorectly, but I'm using Microsoft Visual Studio 2010 for quite some time, and have a strange error, don't know if it's me who's doing the mistake. I cannot seem to include multiple .cpp files into one project. If I do that probably when I run one project it runs both .cpp files and gets a weird error of more multiplication signs being used. Can more .cpp files be included in one project? I guess that it should be able to be done, else it would be very crowded to make a new project everytime you start something new.

Projects can contain multiple *.cpp and *.c files, but only one of those files can contain either main() or WinMain() (depending on whether the project is a console or win32 project). If you are attempting to add multiple files each with their own main() then you are doing it wrong.

In that case, you want to create a blank solution, then add multiple projects to it. Remember, each project creates just one unique executable, library, or DLL. But you can have multiple projects in the same solution. When you want several unrelated programs then I find it just simpler to create separate projects for them. But one solution with multiple projects will work too.

Thanks for the reply.

I'm making a Win32 console application, making it an empty project, and adding a *.cpp file into source files folder.

About declaring main functions, I think that there is probably my mistake. In my second made *.cpp file I also make a main function and should that be a problem? Does when I run the file it reads both *.cpp files?

I tried making a new solution, then making one project, with *.cpp file, when running everything is OK. Then adding a new project to the same solution, also including a *.cpp blank file, writting simple code for displaying the value of an integer, but it executes the first *.cpp file it doesn't even load the second project.

Don't know where the problem might be. I probably didn't get your idea with the multiple projects.

In my second made *.cpp file I also make a main function and should that be a problem?

Yes, that should be a problem. It should be a big problem. You should only have one main function in any given program. If you have more than one main function, how can you tell where to begin execution? I think you need to read up on how a cpp file is turned into an object file and then linked with other object files to form the executable (or library). Once you understand how that works, all your questions about multiple cpp files will be answered.

Does when I run the file it reads both *.cpp files?

You do not run a file. You run a programme. The programme is made out of object files. Object files are made out of cpp files. When you run the programme, the cpp files have nothing to do with it.

Edited 5 Years Ago by Moschops: n/a

First of all, thanks for the replies, I don't know how a simple thing can get me so confused.

About the main function, yes, I knew that it can have only one main function but how does the project know where to start the second project?

About the "how a cpp file is turned into an object file" did some google search but didn't find results, probably wrong access on how to find it. Would you mind sharing where it can be read? This is being a problem for me for a long time, bugging me so that I've been learning general C++ programming but didn't pay much attention of creating the projects, which is also important.

Thanks.

I wouldn't go with the microsoft products because they are too resource heavy, and are too complex for simple things.

the more complex, the more flexible
IMO msvc is a very good compiler since it has a lot of interface facilities, as well as a lot of flexibility

First up, "project" is something of a wooly term that means different things to different people. It commonly seems to mean "a collection of files that I use to make one single binary executable or library".

how does the project know where to start the second project?

When you write cpp files, the compiler turns them into object files. Usually one object file per cpp file. The linker will then take all these object files, and will link them together into a single file (either an executable or a library). If it's an executable, the linker will search the object files for the main function. This is where execution will begin when the programme is run.

So, let's say that in your cpp file, your main function calls a function that is in a different cpp file. The compiler will be happy with this so long as it knows the correct parameter input and return type, which it will know because you either included the right header file, or you pre-declared the function. Essentially, it leaves a note for the linker asking it to hook up the correct function when it's busy linking. When the linker gets busy, that other function is found in the relevant object file and the linker takes care of ensuring that the right function is called (which by this time is making the execution jump over to that piece of binary code with everything set up correctly). If the linker had been unable to find that function, linking would have failed and you would see the well known "unresolved external" error message.

So, now that you know what the compiler and linker do, hopefully you can answer your question yourself.

Note to everyone: I know, I know. There are lots of caveats and edge cases and all that sort of thing. This is meant to be a top-level overview, so please limit your corrections to only the really gross errors I've made :)

Edited 5 Years Ago by Moschops: n/a

the more complex, the more flexible
IMO msvc is a very good compiler since it has a lot of interface facilities, as well as a lot of flexibility

Ironically (and at risk of starting another IDE war :P ), I find MSVC to be too inflexible; I'm used to doing everything on the command-line and with hand-crafted makefiles, which is the ultimate in flexibility. It's all relative :)

Thanks for the reply.

I'm making a Win32 console application, making it an empty project, and adding a *.cpp file into source files folder.

About declaring main functions, I think that there is probably my mistake. In my second made *.cpp file I also make a main function and should that be a problem? Does when I run the file it reads both *.cpp files?

I tried making a new solution, then making one project, with *.cpp file, when running everything is OK. Then adding a new project to the same solution, also including a *.cpp blank file, writting simple code for displaying the value of an integer, but it executes the first *.cpp file it doesn't even load the second project.

Don't know where the problem might be. I probably didn't get your idea with the multiple projects.

Learn to use the right mouse button to acccess additional popup menus. In the Solution Exploror window, select the project name you want to run, press the right mouse button, and you will get several options for that project. Don't be afraid to explore them out to find out for yourself what they do.

Actually, after weeks of searching a simple problem that has been bugging me a lot, I found a simple solution.

Made two projects into one solution, but set one project as a STARTUP PROJECT. This way, it doesn't show any errors, it just runs the one that's set as a startup.

Can't believe that so simple issue, can become so complicated.

Thanks.

This article has been dead for over six months. Start a new discussion instead.