Can't compile C++ in linux mint with Code::Blocks - c++

#include <iostream>
using namespace std;
int main(){
int intake;
cout<<"Enter the maximum number of intake in this session of 2015, September: ";
cin>>intake;
for(int i=20150900; i<intake+20150900; i++){
cout<<"Enter the total percentage of Student ID numbered #"<<i<<": ";
}
return 0;
}
This is my code and when i compile it on code::blocks it gives the following error. I am new to linux OS so i dont know much about how it all works. Thankx for your help! :)
Error Message:
g++ -c /home/subbs/Desktop/entrance_exam/main.cpp -o
/home/subbs/Desktop/entrance_exam/main.o /bin/sh: 1: g++: not found

You need to install the compiler. Run:
sudo apt-get install build-essential
And then, try again to compile.
UPDATE:
If when you're trying to run the program, you get an error message like this:
Process terminated with status 255
It's because code blocks tries to run the program with xterm by default, and it may be the case that you don' have it installed. To solve it you have to go to:
Settings > Environment
And in the drop down menu next to Terminal to launch console programs choose your terminal. In the case of Linux Mint, it was gnome-terminal --disable-factory -t $TITLE -x
- source

Open the terminal and enter sudo apt-get install g++. This will take care of install g++ and everything else you will need. It is real easy.

Related

how to compile c++ program in mac terminal

i wrote a program in my mac using sublime text as the plateform..
#include<iostream>
using namespace std;
int main()
{
cout<<"HELLOW WORLD";
return 0;
}
this was my program..
i saved it in desktop as hellow.cpp
while compiling on mac terminal as g++ hellow.cpp, i found an error
adarshs-MacBook-Air:Desktop adarshak$ g++ hellow.cpp
xcrun: error: invalid active developer path
(/Library/Developer/CommandLineTools), missing xcrun at:
/Library/Developer/CommandLineTools/usr/bin/xcrun
anyone plese help me to find out the error
It sounds like you don't have the command line developer tools installed. Run this command from Terminal once:
xcode-select --install
This will bring up the download & installation UI. Follow this through to the end. (It may take a while depending on the speed of your internet connection.)
From then on compiling should work.

How can I get stdio output when running application as root?

I'm trying to run my application as root because I need to access low level hardware on my computer.
When I run the command:
./application_name
...it works, except gives an error that it needs root. However, when I run this:
sudo ./application_name
...I get no terminal ouput.
I've tested that every time that I run an executable on Linux as root, it doesn't print anything to terminal. How can I fix this?
Edit: somewhat of a test case provided (mobile so can't type out much):
sudo g++ test.cpp -o executable
sudo chmod +x executable
This works on Debian:
./executable
This doesn't:
sudo ./executable
test.cpp:
#include <iostream>
int main() {
std::cout << "Hello World!";
}
That behavior is really strange. Root permissions for that application should have no effect on std output.
For example, I made a simple test, a "hello world" that I ran as root on Debian OS and I had output in terminal.
A simple test to convince yourself that you should have the output, is to make a redirect to a file. For example sudo ./executable > output.txt and you'll see that everything should be OK.
Note that it should be strange if you don't have output from a simple "hello world".

QtCreator returns error "Cannot change to working directory"

I'm trying to running a simple HelloWorld program with Qt Creator
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
When running occurs the error
Cannot change to working directory '/home/myusername/build-myproject-Desktop-Debug': file or directory not found
Many tutorials in the internet tell me to disable "Run in terminal", but I need this for my project.
My working directory is /home/myusername/build-myproject-Desktop-Debug
Any help?
Which OS are you running?
I'm on Linux and had the same problem. My solution was to use xterm and set the default Terminal in Qtcreator to xterm (In the menu: Tools, then Options, then Environment, then Terminal, there "/usr/bin/xterm -e")
You can install Terminator terminal (sudo apt-get install terminator) and use it as Qt Creator terminal:
Tools->Options->Enviroment->System->Terminal->"/usr/bin/terminator -x"

Running Ubuntu Eclipse C++ Helloworld

I'm trying to run a Hello world C++ on Eclipse on Ubuntu 12.04. I installed g++ and wrote this code:
#include<vector>
#include<string>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Compile output:
**** Build of configuration Debug for project TopCoder ****
make all
make: Nothing to be done for `all'.
**** Build Finished ****
Run output message:
Launching TopCoder has encountered a problem
Error starting process
Error starting process.
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
Exec_tty error:Cannot run program "/media/01CCE00FA6888D80/Achieve/Eclipse/TopCoder/Debug/TopCoder": Unknown reason
when I put the source code on ext4 drive it builds and run
I changed
proc /proc proc nodev,noexec,nosuid 0 0
in /etc/fstab to
proc /proc proc dev,exec,suid 0 0
But no usefulness.
You're tring to run an application from the /media/01CCE00FA6888D80 volume. Removable USB? The most likely culprit is noexec as an option to the default mount command line.
check if noexec is part of the options for mounting the filesystem using:
grep noexec /proc/mounts
if this results in output indicating that noexec is in effect for the file system then try:
sudo mount -o remount,exec /media/01CCE00FA6888D80
Also, if the removable volume is NTFS, your milage may vary.
Try to build it from the command line. Then you will know if the problem is involved with g++ or with eclipse. I guess you should change your compiler path somewhere in the eclipse, are you sure you have eclipse-cdt? THe easiest way to compile it is:
g++ yourfile.cpp
Your problem is that you're workspace is probably on a different drive than the one you installed ubuntu on
You are running you project over Linux . i had facing same issue when my project was in my E drive . i gave read -write permission but still that was not enough for me . The same error was keep coming when i was trying to run the project .
I have shifted my project in my Home folder ,gave permission and the project ran !! .
I believe there was a problem with some permission for LINUX C compiler .

C++ compiles but gives error when executed

I am new to Linux Ubuntu 11.10 and have basic C++exposure.
I installed the g++ by
sudo apt-get install build-essential
and created a directory cpp in my home directory. I then wrote a program hello.cpp in my cpp directory
#include <iostream>
using namespace std;
int main() {
cout << "Hello !" ; return 0;
}
and compiled using
g++ -W hello.cpp -o hello
The program compiles without any errors/warnings. When I try to execute the file
./hello.cpp
I get error messages:
line 3: using: command not found
line 6: syntax error near unexpected token `('
line 6: `int main() {'
I tried looking at a lot of posts but could not resolve this. I have MS VisualStudio on Windows, but I would rather learn C++ on Ubuntu. Thanks in advance.
I think that the problem is that you're trying to execute the .cpp source file rather than the generated executable. Try running ./hello instead of ./hello.cpp, since hello is the actual executable. The errors you're currently getting are caused by the shell interpreter choking on C++ syntax, since it's trying to run it as a shell script.
Hope this helps!