Codeblocks C++ project won't build or run
I am a new Ubuntu user. I started C++ programming in Windows using Code::Blocks, and would like to try the open source environment of Linux.
I am looking to set up Code::Blocks IDE to develop in C++. I have installed it and used it to create my first hello world application in Ubuntu. I tried to compile and run it, but it has a debugger issue and what appears to be a link issue. When I first started the first C++ test.cpp project, it asked me what compiler to use, and it automatically detected the GNU GCC Compiler which I selected.
Do I need to download anything from the repository to get my C++ code to run in Code::Blocks? Do I need to link anything in my build options that isn't done automatically?
22 Answers
Your C++ program is not running in Code::Blocks because you do not have a C++ compiler (a version of G++) installed, or if it is installed you have not configured the C++ compiler in the Code::Blocks compiler settings. The C++ compiler is not configured for any version of g++ by default, so it has to be configured in the Code::Blocks compiler settings.
Install the g++ compiler for C++
sudo apt install g++ xtermOptionally install gcc too if it is not already installed.
sudo apt install gccStart Code::Blocks.
- Select Settings -> Compiler -> Global compiler settings (large blue gear icon in the left pane) -> Toolchain executables tab.
- Select the Program Files tab. It has already been selected in the below screenshot.
- Click the .. button(s) which are marked by the mouse cursor in the below screenshot. Navigate to
/usr/bin. The C compiler should begcc, the C++ compiler should beg++and the Linker for dynamic libs should beg++. - Click the OK button to close the Compiler settings window.
Note: It is permissible to install later versions of gcc and g++ from the default Ubuntu repositories alongside gcc and g++ and select them instead of gcc and g++ in the Code::Blocks compiler settings. The latest versions of gcc and g++ in 19.10 and 20.04 are gcc-9 and g++-9.
Basically, Code::Blocks doesn't require any additional configuration.
You should have installed g++ package. You can do it by issuing command
sudo apt-get install g++