views:

372

answers:

7

Greetings,

I am trying to figure out which C/C++ compiler to use. I found this list of C/C++ compilers at Wikipedia:

http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers

I am fairly certain that I want to go with an open source compiler. I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better. Please tell me if you disagree.

I should mention that I plan on learning C/C++ mainly to program 2D/3D game applications that will be compatible with Windows, Linux, MAC and iPhone operating systems. I am currently using Windows Vista x64 OS.

Thanks, Adam

+14  A: 

Use gcc and g++ while you're still learning these languages, a big enough task for now. If you need a specialized compiler down the road, you'll want to have much deeper understanding of the language and your problem domain to properly evaluate candidates.

Greg Bacon
+1… GCC leads in compliance and portability.
Potatoswatter
@Potatoswatter: compared to what?
jalf
Using gcc and g++ on their own is a hassle that you shouldn't have to deal with when learning. The benefits of a proper IDE, with built in debugging, build management, and such simply can not be ignored while you are still learning the language. Simply using g++ doesn't magically make your code portable, after all; you still have to chose cross-platform libraries.
Dennis Zickefoose
IMHO IDEs are terrible for learning: you end up with tons of code not created by you that you don't really understand.
Lo'oris
@Lo'oris: What you mean to say is that "code wizards" and the like are terrible for learning. Don't throw out the baby with the bath water; code generation is the least important part of a good IDE.
Dennis Zickefoose
I will admit that using VS can make it more difficult to understand the compilation process; its easier to understand linker errors for instance if you have to build things by hand a few times. But in my experience, people using command line tools to learn end up either ignoring multiple source files, or else using a build process that boils down to `g++ *.cpp`, neither of which are much more useful than just letting the IDE handle the tricky parts.
Dennis Zickefoose
+6  A: 

Get the Visual Studio Express (easier and quicker IMO, to setup) and learn with it; when you think you know enough about C++ and how "things" work, you could start using something like QT or GCC (with cygwin) and learn to port to different platforms.

Max
The toolkit is called Qt (upper Q, lower T); QT is QuickTime (upper Q and T).
iconiK
I see. Perhaps you are right. After all I am just a beginner. Something to consider certainly. Thanks.
J3M 7OR3
+10  A: 

First of all, IMHO as a beginner your development environment (IDE) matters a lot more than the compiler.

I think that people place too much emphasis on compiler choice early on. While it is not Java, C++ is meant to be portable.

If the program you're writing only works with specific compilers, you're probably doing the wrong thing or can work a little on making it more portable.

If you get to a point where compiler choice makes a significant performance impact for you, then you've already perfected everything else in your program and you're in a good state and you are also quite advanced in your abilities. We used to teach the differences between compilers at fairly advanced stages in the CS curriculum.

If you use a UNIX based machine (Linux, Mac, actual Linux), then pretty much GNU (g++) is the way to go and is fairly much standard. If it's good enough to compile your OS, it's probably good enough for you. On a mac you can use XCode as your IDE, and it interfaces well with g++. On Linux some people prefer command line tools, though you might like the Eclipse C++ support, it is much better today than it was 3-4 years ago.

Things on Windows are trickier. If you can afford it, have access to, or are eligible for one of the free editions (e.g., via a school), I think the Microsoft Visual C++ Environments (or whatever they are called now) are pretty good for learning and they are used in production. I think there's actually a lightweight visual studio now with an emphasis on C++ that could be a good start. If you don't, you can probably find a distribution of Eclipse that is specific for C++ and includes an implementation of the GNU compilers.

Uri
I am using Windows Vista x64. I searched for the best IDE for C/C++ and most people are saying Microsoft Visual Studio but, I want to develop for all operating systems, not just Windows OS (XP/Vista/7). I have read that it is important to consider portability when choosing an IDE.
J3M 7OR3
If you're developing a game, you'll probably be using a 2D/3D graphics API that is proprietary to a platform, like DirectX vs. OpenGL vs. Whatever is used on the iPhone. If you're just learning C++ and using standard libraries, then your code will easily be portable regardless of the OS or compiler that you use.
Uri
@Adam: No, portability is almost completely orthogonal to IDE choice IMO. Pick your favorite IDE, use it to write portable code (ie avoid compiler extensions that come with the IDE's compiler), then when you're done take that code and compile it on your other target platforms, possibly using a different compiler.For instance, I write most of my programs using Visual Studio, then use gcc to compile the project on OS X/Linux. The downside is that when I port I have to write a separate makefile (MSVC doesn't use them), which is a pain but worth it.
+1 @user168715 I completely agree with this sentiment, although I tend to go the other direction (write using vim, build/debug mostly using GNU tools, build/test on Windows, backport any changes to Linux, repeat until the same codebase works on both). Slight disagreement - MSVC *does* support Makefiles (I use this to build using VS2008, but with the VC7.1 compiler), they're just not in entirely the same form as GNU makefiles :/.
Nathan Ernst
Also, if you wanted to use a GNU makefile, it is technically possible, but you'd have to build using an external command rather than internal targets, and your experience using VS as an IDE is going to rapidly diminish...
Nathan Ernst
+6  A: 

I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better.

That's not necessarily true. You could also say that if you use Microsoft's compiler, it will be optimal for Windows, since Microsoft knows best how to optimize a compiler for Windows.

Microsoft has Visual C++ Express Edition which is free and ofcourse includes a nice IDE that's very well suited for Windows development.

But if you're interested in making portable software, look at GCC, which is the default compiler on Linux and which is also available on the Mac. (The iPhone works totally different and requires special tools that only run on Mac OS X). You can get GCC for Windows with Cygwin or MinGW.

Jesper
Well I plan on taking all the C/C++ code I write on my Windows Vista machine over to the MAC environment at a later date. I don't think Visual C++ Express will be a smart choice for me to start out in. I might as well just jump right into GCC and Cygwin. What IDE would be well suited for GCC for Windows and Cygwin?
J3M 7OR3
There is for example Code::Blocks http://www.codeblocks.org/ which is free and available for Windows, Linux and Mac OS X. You could also use Eclipse or NetBeans for C++ developments, although those are primarily Java IDEs. You need to install GCC on your system and then those IDEs will use that to compile your code.
Jesper
Cygwin is nice, but may be a problem if you are developing commercial applications.
George Edison
You can use gcc (mingw) on windows without Cygwin
rmeador
Cygwin is a bad choice if you want truly portable code - it can easily push you towards Unixisms. MinGW is a decent middle ground. That said, if you stick to a reasonable subset of standard C++ (the only thing to be wary of are exception specifications), you can compile with MSVC on Windows and g++ elsewhere. I worked in such a (production) environment for two years in the past, and we had a very large codebase which was handled that way without much trouble.
Pavel Minaev
A: 

For windows u can use CodeBlocks I believe it uses gcc and its pretty user friendly

rabidmachine9
On Windows, actually, Code::Blocks comes with MinGW :)
George Edison
+1  A: 

I strongly suggest going with MinGW.

It is:

  • Open-source
  • Available on all major platforms
  • Comes with standard Win32 headers and libraries
George Edison
Available on all major platforms? Does that mean it is available for linux :p
hhafez
MinGW is a particular build of gcc for Windows.
Ben Voigt
@hhafez: It is available for Linux. In fact, a lot of people use it to build Windows applications on Linux. Then they test them in WINE.
George Edison
Ofcourse it's not available for linux, MinGW is specifically for windows (hence windows) so not it's not available for all major platforms, what is available for most major platforms is GNU software which is not equivalent to minGW
hhafez
@hhafez: MinGW **is** available for linux - check your package manager - it'll be there.
George Edison
What you are talking about is a cross compiler on linux to build mingw binaries, that is different than what I thought you meant (mingw enviroment on linux). They are two different things but I know what you mean now
hhafez
@hhafez: Sorry for the confusion :)
George Edison
A: 

The key to writing portable C++ code is:

  • Use a cross-platform version control system (subversion is a great choice), because this makes it easier to
  • Compile and test your code on other platforms early and often
Ben Voigt