CodeBlocks in Ubuntu 18.04 doesn't show any result in Console after Build and Run. What should I do?

10,210

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.

  1. 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 
    
  2. Start Code::Blocks.

  3. Select Settings -> Compiler -> Global compiler settings (large blue gear icon in the left pane) -> Toolchain executables tab.
  4. Select the Program Files tab. It has already been selected in the below screenshot.
  5. Click the .. button(s) which are marked by the mouse cursor in the below screenshot. Navigate to /usr/bin. The C compiler should be either gcc or optionally gcc-8, the C++ compiler should be g++-8 and the Linker for dynamic libs should be g++-8.
  6. Click the     OK     button to close the Compiler settings window.

enter image description here

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.

enter image description here

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.

Share:
10,210

Related videos on Youtube

Rafid Haque
Author by

Rafid Haque

Updated on September 18, 2022

Comments

  • Rafid Haque
    Rafid Haque over 1 year

    Output from CodeBlocks

    I have just switched to linux.

    Thanks in advance!

    • Joshua Besneatte
      Joshua Besneatte almost 6 years
      have you installed build-essential? sudo apt install build-essential from the command line?
    • Rafid Haque
      Rafid Haque almost 6 years
      yes... didn't work :(
    • Joshua Besneatte
      Joshua Besneatte almost 6 years
      didn'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
      Rafid Haque almost 6 years
      what 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
      Joshua Besneatte almost 6 years
      what's in those other tabs? code-blocks, debugger, etc?
    • George Udosen
      George Udosen almost 6 years
      Is xterm installed? As I tried to install codeblacks and it needs xterm!
    • Rafid Haque
      Rafid Haque almost 6 years
      woah george that was the thing! xterm wasn't installed! you are a life saver!
  • Rafid Haque
    Rafid Haque almost 6 years
    did 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
    Joshua Besneatte almost 6 years
    what happens if you change the debugger?
  • karel
    karel almost 6 years
    I 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
    karel almost 6 years
    gdb 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
    Rafid Haque almost 6 years
    everything was fine... XTerm was supposed to be installed to show the console... phew who knew...
  • Joshua Besneatte
    Joshua Besneatte almost 6 years
    wait, so the answer is to install XTERM? as in the answer here is not correct?
  • karel
    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
    Joshua Besneatte almost 6 years
    right... 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
    Joshua Besneatte almost 6 years
    seems like this is the actual correct answer....
  • karel
    karel almost 6 years
    Even 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.