Friday, November 7, 2008

Making Code::Blocks work in a Linux Box



Linux C/C++ programmers do most of their programming work in the terminal. From editing files, compiling, testing and debugging. There are lots of good command line editors, I must say, complete with syntax highlighting and the features you would expect from an editor. With an additional capability to handle syntax highlighting for different programming languages. One that I like most is vim. But the use of the stuff is way "too advanced" for others and sometimes causes them to "panic" for the first programming tasks. If the user is used with the "nice" IDE of "other" operating system, it would think "Linux is not the right stuff for me."

But hey, think again, the thing that you like in that "other" operating system could also be found in Linux. And one program that could provide you with such a functionality is Code::Blocks. You can find more detail here.

To install codeblock, do this:


for Fedora:
sudo yum install codeblocks

for Ubuntu:
sudo apt-get install codeblocks

During the first run, it will automatically detect the installed compiler in your system (i.e.,GNU GCC Compiler). Then it will show you its interface, nice!

But when you compile your first program, it may seem odd that the IDE is issuing error messages. You then begin to wonder the occurrence of such a thing when all the necessary compiler are already installed. One thing to note is that, even though it detected the kind of compiler that you have during the first run, it still needs to know the locations of the compiler. This is necessary as some Linux systems has different C/C++ compiler directory structure. The way to solve the aforestated problem is to set-up the necessary info in order for the IDE to work. How? Follow these steps:

1. On the menu, go to Settings --> Compiler and Debugger. It will show you the window:



2. Find the tab, which has the label Toolchain executables.
3. In the textbox under the "Compiler's Installation Directory" type the location of your C/C++ compiler binary. If you don't know it, open a terminal and type:

whereis g++

this command will return the location of g++ compiler and its manual file. For example, in my Fedora 9 box it returns:

g++: /usr/bin/g++ /usr/share/man/man1/g++.1.gz

You only need to take note of this /usr/bin/g++. Because this means that g++ is located in /us/bin directory as well as the other compilers. And this is the information you need to provide to codeblocks. After typing this info, click the OK button.

The next time you compile in codeblocks it will now be able to run your C/C++ code (of course, provided that your program does not contain any error during compilation.)


No comments: