0

So i just installed code blocks on Lnux mint 19, but i have a problem. I ran the usual hello world program, but got "Process terminated with status -1". The "build" part works, but when i hit the "run" i get that error. I have g++ installed and set as default compiler. Any idea?

Tried everything i could find on the internet. Added the rep, tried installing from both the software center and from the terminal, same result.

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

Process terminated with status -1

2 Answers2

0

From what I can tell, from the minimal amount of code you've posted, you're missing includes. If you're not missing includes, you're not telling your compiler where cout and endl are.

Your code should look like this:

#include <iostream>

int main() {
    using std::cout;
    using std::endl;

    cout << "Hello, World!" << endl;

    return 0;
}

Here's a brief explanation.

#include <iostream> Tells the preprocessor to load this header file in to your translation unit (CPP file), so you have all the forward-declarations required to use the different objects, functions, and other members of the STL.

using std::cout && using std::endl These two pieces of code tell the compiler specifically which members of the std namespace you wish to use. I'd recommend using this method (even though it may seem tedious), rather than using namespace std;. By using the entire namespace, you're polluting your global namespace in this case.

See this question for some more examples as to why you should avoid using namespace.

SimonC
  • 1,547
  • 1
  • 19
  • 43
0

Your default Linux terminal seems to be incompatible with the calling C function. Try to install a plain xterm additionally to your main terminal:

$ sudo apt install xterm

Try running your code now.

In case it doesn't help, you can also try to change your default terminal in codeblocks: Go to Settings > Environment > General Settings, and change the terminal to "gnome-terminal" for example.

If that fails, the actual X display error will be helpful for further troubleshooting:

$ tail -f ~/.xsession-errors

Try running your code now and check your terminal for the latest xsession error. Most likely, it will start with "Error setting file metadata:" There you may find the full error message.