LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-08-2011, 06:21 AM   #1
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Rep: Reputation: Disabled
need help with cpp


I i'm trying to start using the g++ compiler again. I read a tutorial and got started. This is what I get in the terminal

--------------------------------------------

bash-4.1# g++ helloworld.cpp -o helloworld
bash-4.1# ./helloworld
bash: ./helloworld: Permission denied

------------------------------------------------

I guess that the file extension should be cpp. It looks like it compiles it just won't run

here is the program that comes from the tutorial i just don't know if it is right for this compiler

-----------------------------------------------

// structure

// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}
 
Old 06-08-2011, 07:54 AM   #2
bosth
Member
 
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304

Rep: Reputation: 127Reputation: 127
It's probably a mask problem. First thing, let's check the permissions on the binary:
Code:
$ ls -l
What does it say for your compiled binary?
 
Old 06-08-2011, 08:07 AM   #3
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
it says helloworld
 
Old 06-08-2011, 08:07 AM   #4
bosth
Member
 
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304

Rep: Reputation: 127Reputation: 127
What does the whole line say?

In case it isn't clear, that is a lower case 'L' not the number '1' in the command.

Last edited by bosth; 06-08-2011 at 08:09 AM. Reason: add clarification
 
Old 06-08-2011, 08:11 AM   #5
zoran119
Member
 
Registered: Dec 2007
Posts: 217

Rep: Reputation: 18
chmod +x helloworld
./helloworld
 
Old 06-08-2011, 08:16 AM   #6
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
the line says

-rw-rw-rw- 1 root root 6819 June 8 06:12 helloworld

---------- Post added 06-08-11 at 08:17 AM ----------

zoran what's that going to do?
 
Old 06-08-2011, 08:18 AM   #7
bosth
Member
 
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304

Rep: Reputation: 127Reputation: 127
Zoran's command will work then. But what you should do is compile your code as a user other than root. The reason you can't run the binary after compiling is that there is a security measure in Linux to protect your system from running malicious code. You could change this setting (read about umask), but if you log in as another user your system will be safer and your code will run.
 
Old 06-08-2011, 08:21 AM   #8
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
Thank you both. I got it from here.
 
Old 06-08-2011, 08:42 AM   #9
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
It's not that simple. I made a user account. I get the same Permission Denied. I tried recompiling it and still the same.

I tried chmod +x helloworld and i get this

chmod changing permissions of 'helloworld': Operation not permitted
 
Old 06-08-2011, 08:45 AM   #10
brixtoncalling
Member
 
Registered: Jul 2008
Location: British Columbia
Distribution: Slackware current
Posts: 403

Rep: Reputation: 67
I wonder if you mounted your file system to be no execute? What does the command "mount" report?
 
Old 06-08-2011, 09:00 AM   #11
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
/dev/root on / type ext4 (rw,relatime,barrier=1,data=ordered)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/dev/sda7 on /penguinpower type ext4 (rw)
/dev/sda2 on /windows7 type fuseblk (rw,allow_other,blksize=4096,default_permissions)
/dev/sda4 on /files type fuseblk (rw,allow_other,blksize=4096,default_permissions)
tmpfs on /dev/shm type tmpfs (rw)
 
Old 06-08-2011, 09:04 AM   #12
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
are these fine in the source code:

#include <iostream>
using namespace std;

I'm really not all that experienced but I did make a B on my college c++ course. The class lacked on libraries.

The reason I am asking is because I didn't install any libraries other than what came on the slackware DVD. I installed everything

Last edited by DarbieL; 06-08-2011 at 09:08 AM.
 
Old 06-08-2011, 09:08 AM   #13
bosth
Member
 
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304

Rep: Reputation: 127Reputation: 127
Hang on... what directory are you doing this in?
 
Old 06-08-2011, 09:13 AM   #14
DarbieL
LQ Newbie
 
Registered: Jun 2011
Posts: 21

Original Poster
Rep: Reputation: Disabled
I am doing the programming in /files/penguin\ power/

/files is a partition mounted

if you were asking about when i typed in mount in the command line I did that in the home directory
 
Old 06-08-2011, 09:21 AM   #15
bosth
Member
 
Registered: Apr 2011
Location: British Columbia, Canada
Posts: 304

Rep: Reputation: 127Reputation: 127
Try compiling your code in your user's home directory: /home/USER_NAME
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cin in cpp , milky.way Programming 4 12-08-2007 10:16 AM
debian dpkg cpp depends on cpp error darkleaf Linux - Software 2 06-25-2004 01:47 AM
cpp error ANU Linux - Software 1 12-05-2003 11:24 PM
cpp: pointers Wonko the Sane Programming 3 11-17-2003 03:38 AM
Now I have gcc/cpp/cpp, but still can't install sfingerh Linux - Software 2 07-30-2002 03:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration