CodeBlocks in Ubuntu 18.04 doesn't show any result in Console after Build and Run. What should I do?
Solution 1
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++ in Ubuntu 18.04 by default, so it has to be configured in the Code::Blocks compiler settings.
-
Install the latest version of the g++ compiler for C++.
sudo apt install g++-8 xterm
Optionally install the latest version of gcc too (recommended).
sudo apt install gcc-8-base # recommended version
Start 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 be eithergcc
or optionallygcc-8
, the C++ compiler should beg++-8
and the Linker for dynamic libs should beg++-8
. - Click the OK button to close the Compiler settings window.
Solution 2
I tried to install codeblocks
in bionic and it was almost a night mare as so many dependencies are needed. In the case of the question OP was missing the xterm terminal
that codeblocks
uses to work and that can be found in the libwxbase3.0-0v5
package, when you try to install this it will complain then you run sudo apt install -f
and it will install xterm
as part of the dependencies.
Please note that the codeblocks
download comes with the dependencies needed in the archive filecodeblocks_17.12-1_amd64_stable.tar.xz
from their down load site.
Related videos on Youtube
Rafid Haque
Updated on September 18, 2022Comments
-
Rafid Haque over 1 year
-
Joshua Besneatte almost 6 yearshave you installed build-essential?
sudo apt install build-essential
from the command line? -
Rafid Haque almost 6 yearsyes... didn't work :(
-
Joshua Besneatte almost 6 yearsdidn't work, as in, the install didn't work or it didn't fix your problem? what does the debug tab say? have you tried to build/run your program from the command line?
-
Rafid Haque almost 6 yearswhat i meant was that the package was already installed. And it didn't solve the problem I am having with CodeBlocks. (it is not showing the output in console)
-
Joshua Besneatte almost 6 yearswhat's in those other tabs? code-blocks, debugger, etc?
-
George Udosen almost 6 yearsIs
xterm
installed? As I tried to install codeblacks and it needs xterm! -
Rafid Haque almost 6 yearswoah george that was the thing! xterm wasn't installed! you are a life saver!
-
-
Rafid Haque almost 6 yearsdid all that... but still no result in console... in the build log, the message is ------------- Run: Debug in hello_linux (compiler: GNU GCC Compiler)--------------- Checking for existence: /home/rafid/Desktop/Study Materials/Code/C++/hello_linux/bin/Debug/hello_linux Executing: xterm -T hello_linux -e /usr/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/rafid/Desktop/Study\ Materials/Code/C++/hello_linux/bin/Debug/hello_linux (in /home/rafid/Desktop/Study Materials/Code/C++/hello_linux/.) Process terminated with status -1 (0 minute(s), 0 second(s))
-
Joshua Besneatte almost 6 yearswhat happens if you change the debugger?
-
karel almost 6 yearsI think you either have messed up the existing hello project or else you have not yet created a new hello project in Codeblocks. Select File -> New -> Project -> Console application -> click Go button and follow the new project wizard to the end. First delete the old hello project so it doesn't interfere with the new hello project. And type the C++ code in main.cpp from scratch so you don't copy any Windows line endings which don't work in Ubuntu.
-
karel almost 6 yearsgdb is the default debugger and it always works perfectly in Code::Blocks. You can change the default debugger of course, but that should be asked as a separate question. Let's get this program working with gdb first. Afterwards you can ask how to install a different debugger and configure it in Code::Blocks. Your C++ code in your question is OK, so you won't need gdb yet for this code.
-
Rafid Haque almost 6 yearseverything was fine... XTerm was supposed to be installed to show the console... phew who knew...
-
Joshua Besneatte almost 6 yearswait, so the answer is to install XTERM? as in the answer here is not correct?
-
karel almost 6 years@JoshuaBesneatte You can't run C++ programs without installing some version of g++, not in Code::Blocks and not even from the terminal. Code::Blocks uses the Intel C/C++ Compiler for compiling C++ code by default, which is not available in the default Ubuntu repositories, so you need to install g++ instead.
-
Joshua Besneatte almost 6 yearsright... but i was more commenting on OPs comment... what actually fixed his problem was installing xterm as the C compilers were already installed when he installed build essential.
-
Joshua Besneatte almost 6 yearsseems like this is the actual correct answer....
-
karel almost 6 yearsEven if you already have g++ installed, Code::Blocks still won't compile C++ code until you configure it for C++ in the Code::Blocks compiler settings. Code::Blocks was originally written for Windows, so it often tries to do everything the same way it is done in Windows by default until you configure it.