The Frustration is in the Compiling

Hi all. So I'm fairly new to C++, and programming in general. As far as languages go, I'm familiar with TBASIC and programming calculators, but that's about it. I decided to get into C++, cause I've heard such great things about it. I started by reading through the tutorials on this site, with great success. I'm coming to grips with the language, and some of the concepts. It's just... I'm having some issue compiling.

I've looked a few places online, with little success. A few places I've looked have led me to think that I could use the java console command 'javac' but I don't think that's right. Especially because I've tried it, and it didn't work haha.

If anyone could clear up my confusion, or even point me towards a great compiler, that would be AMAZING! Thanks in advance.

Best compiler out there for beginners!

For more proffessional use. I would suggest Microsoft's visual studio compiler.
Sweet, I'm downloading that right now. One question though; let's say that I'm a professional C++ coder, working on a huge project. What would be wrong with using CodeBlocks for that higher level compiling?

Maybe a better way of saying this; how can one program compile 'better' than another?
It's not really that one compiler is better than another. CodeBlocks just allows you to... How should I put this... Write more freely.

Visual Studio is more strict in syntax, and one little syntax mistake can cause it to not compile.

CodeBlocks allows some exceptions, which I find great.

The reason why you would pick Visual Studio over CodeBlocks, is because, Visual Studio has access to more advanced stuff in it's compiler.

I personally use CodeBlocks myself, and I'd say it's great! Better than Visual Studio. But that's because I'm a beginner ;)

Proffessionals would probably pick Visual Studio over CodeBlocks. If you're a beginner, pick CodeBlocks. And I know some beginners would still pick Visual Studio over CodeBlocks, because they think they can "handle it", sure you can, but you're just making it alot tougher for yourself if you're not experienced.
Okay, I see what you're saying. I really appreciate your help, I know what it's like to help someone who's totally new to something, a little tedious :P

So I can't find a 'compile' button, but I did find a build button. Is that the same thing? I think it is, because there's also a button that says build and run. When I click either of them though, nothing happens. I also saw something about a build target, like a directory maybe? However, when I click on the box that says 'Build target,' it's disabled.

Am I making sense? Hahaha
If I understand correctly, you've installed CodeBlocks and are looking on the editor in the compiler? ;)

If so, try write a "Hello world" program and press F9. F9 automatically goes to build->build & run.

Try putting in this code:

#include <iostream>
using namespace std;

int main(){
cout << "Hello world!" << endl;

If it works, then congratz! You've built your first program in the compiler! :)
Last edited on
Nothing happens when I press the button :O

Also, I went to settings>Compiler and it says that the GNU GCC Compiler directory cannot be found. Did I get a bad install or something?
How to compile c++

I'm not sure how you found "javac" and nothing else, as googling for "how to compile c++" find loads of good site, the first three of which are:

How to: Compile a Native C++ Program from the Command Line

How to Compile in windows?

How to compile a C/C++ program

There are also several threads on best compiler and best IDE on this site!

Compiler versus IDE

Note that Code::Blocks isn't a compiler, it's an IDE (Integrated Development Environment)

Code::Blocks uses the GCC compiler set, default, as do a lot of other IDEs. So whether you use Code::Blocks, CodeLite, Geany, ... or even the command line, the compiler is the same, which means that the program will be compiled identically (for the same compiler version and command line switches)


Q1 Do you want to the compiler directly (at the command line) or would you prefer to use an IDE?

Q2 What platform are you using?


The GCC compiler is a very good and popular compiler.

If you're using Linux (or Mac, I presume) then you also have the Clang compiler, which has a good reputation.

(Note: that while Clang had better C++11 support than GCC< apprently this is no longer the case: data March 14, 2013

C++11 compiler support shootout: Visual Studio, GCC, Clang, Intel

If you're using Windows, then you should also consider using Microsoft's Visual C++ Compiler. Unfortunately Clang is not yet fully stable on Windows (last I heard).

Note that Code::Blocks, CodeLite, Geany, ... can be used with all these compilers. It's even possible with Visual Studio, but not so neatly.

Last edited on
As far as actually coding, I like using Notepad++. However, that is also not a compiler. However I end up compiling my code, I don't really care as long as it works in the end.

I'm using Windows 7 x64.
Are you talking about coding single cpp files? Or projects with multiple files?

If you're just compiling a single file, you can easily invoke the compiler directly against the file on the command line.

If you've installed Visual Studio C++ Express (the IDE plus compiler)...

(You used to be able to get the compiler toolset without an IDE, but now the Express versions are available for free, I think that's no longer the case.

The latest version of Visual C++ Express (just C++) is 2010:

There is the more recent "Visual Studio Express 2012 for Windows Desktop"
"to build powerful desktop apps in C#, Visual Basic, and C++"

If you need C++11 feature, then use the latter.)

You need to open a Visual Studio command prompt (so that the required environment variable have been set) then

C:\MyProjects\simple\cl /EHsc simple.cpp

How to: Compile a Native C++ Program from the Command Line

If you've installed the MinGW GCC toolset...

(The Minimalist GNU for Windows port of the GNU Compiler Collection: this can be installed on it's own, or as part of a bundle with an IDE like Code::Blocks or CodeLite. From the Code::Blocks binary download page:

The codeblocks-12.11mingw-setup.exe file includes the GCC compiler and GDB debugger from TDM-GCC (version 4.7.1, 32 bit).

Which sounds like good value, as you also get a debugger!)

And set up your environment so that the compiler, so it can be found, then running the following from the command line will build an executable.

C:\MyProjects\simple\g++ simple.cpp

How to compile a C/C++ program

Note that while you can run the compiler from a regular Windows command prompt, if you want to use some of the other GCC tools, you will have to work from a MSYS shell (MSYS, a contraction of "Minimal SYStem").


Last edited on
I DID IT! YES! Thank you so much for your help. I installed the MinGW toolset, and I even set up my environment all by myself! I compiled my Hello World program through command prompt using

g++ HelloWorld.cpp

I'm so excited, I can finally get going onto bigger things that just 'Hello World' haha. Thank you for your help.
Topic archived. No new replies allowed.