PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

./ProgramName results in "Permission denied"

Wed Feb 10, 2016 12:06 am

I just put together my first Raspberry Pi. This is the 2B version. I downloaded and installed the latest Raspbian Jessie using NOOBS_v1_5_0.zip. I am a Linux newbie so the CLI is unfamiliar to me. I have managed to format and mount an old 200GB USB hard drive so I have lots of storage. I am able to create files and edit them using the text editor that came with the desktop apps. I have also been able to compile a "Hello World" CLI program using the pre-installed GCC. Following Bruce Smith's "Raspberry Pi Assembly Language" I try to run the program in a "terminal window" which is apparently a CLI running Bash. Typing in "./ProgramName" I get a failure: "bash: ./ProgramName: Permission denied". Right-clicking on the HD in the file manager app I select the "Properties" option and the "Permissions" tab. The "View content", "Change content" and "Access content" selectors all have "Only owner" selected. If I change them all to "Anyone" and then dismiss the panel with the "OK" button, I don't get any complaints. But when I bring that panel up again, all of the selections are back to "Only owner". Are these bugs in the system or am I doing something wrong?

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 8:20 am

Some file systems don't support Linux permissions and mount with a static set, so use sudo, or mount, or mkfs
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 9:05 am

Try...

Code: Select all

sudo ./ProgramName
Just incase the instructions didn't explain that you need to make the file executable first, try...

Code: Select all

sudo chmod +x ProgramName
... then try running it again as above.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
rpdom
Posts: 17172
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 9:22 am

sudo should not be needed for a simple "Hello" program. Something else is wrong, possibly file system permissions.

By default, gcc seems to generate output files with the correct permissions. I just tried creating a simple C program

Code: Select all

#include <stdio.h>

int main()
{
    printf( "Hello Raspberry World\n" );
    return( 0 );
}
compiling it with gcc

Code: Select all

pi@raspi3 /tmp $ gcc -o hello hello.c
then running it

Code: Select all

pi@raspi3 /tmp $ ./hello
Hello Raspberry World
Permissions of the file created were rwxr-xr-x (755). That was enough

Code: Select all

pi@raspi3 /tmp $ ls -l hello
-rwxr-xr-x 1 pi pi 5732 Feb 10 09:17 hello

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 10:17 am

Yes. My bad. I didn't read the opening post properly and spotted "bash: ./ProgramName: Permission denied" leading me to believe it was a BASH file that needed a manual permissions change. More coffee required, me thinks! :D
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 1:15 pm

> Some file systems don't support Linux permissions and mount with a static set, so use sudo, or mount, or mkfs

I wrote "I have managed to format and mount an old 200GB USB hard drive ". I used mkfs.ntfs first and then mkfs.vfat. I got the same result from both attempts. Most of my other systems run Windows 7 so I needed a file system that they can read.

User avatar
rpdom
Posts: 17172
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: ./ProgramName results in "Permission denied"

Wed Feb 10, 2016 2:05 pm

Give the file system permissions with the mount command or in the fstab if you're using that.

Code: Select all

pi@raspi3 ~ $ sudo mount -o fmask=0,uid=pi /dev/sda1 /media
pi@raspi3 ~ $ cp /tmp/hello /media
pi@raspi3 ~ $ ls -l /media/hello
-rwxrwxrwx 1 pi root 5732 Feb 10 14:03 /media/hello
pi@raspi3 ~ $ /media/hello
Hello Raspberry World

PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

Re: ./ProgramName results in "Permission denied"

Tue Feb 23, 2016 4:01 pm

>Some file systems don't support Linux permissions and mount with a static set, so use sudo, or mount, or mkfs
I did all of this and my system has the same behavior. I even reformatted the drive to ext3 and ext4 which are unix formats. The system still refuses to run the program. I have even created a subdirectory under pi and copied the files to the native file system so that I have even taken the USB drive out of the loop and it still has the same behavior. Setting the attributes of the file to 777 has no effect. I think it is a bug in the Raspbian distribution.

PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 4:25 pm

> Permissions of the file created were rwxr-xr-x (755). That was enough
> Code: Select all
> pi@raspi3 /tmp $ ls -l hello
> -rwxr-xr-x 1 pi pi 5732 Feb 10 09:17 hello

I reinstalled Raspbian from NOOBS again to make sure the state of the system is exactly as it is freshly installed.

This is what I did just now:
pi@raspberrypi:~Apps $ chmod 755 hello
pi@raspberrypi:~Apps $ ls -l
-rw-r--r-- 1 pi pi 0 Feb 28 16:09 save.txt
-rwxr-xr-x 1 pi pi 5976 Feb 28 16:00 hello
-rw------- 1 pi pi 5832 Feb 28 16:00 hello.a
-rw------- 1 pi pi 106 Feb 28 16:00 hello.c

pi@raspberrypi:~Apps $ ./hello
Inconsistency detected by ld.so: dl-lookup.c: 871 _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask nwords - 1)) == 0' failed!
pi@raspberrypi:~Apps $

I also did this and it didn't solve the problem (but it didn't complain):
pi@raspberrypi:~Apps $ sudo chmod +x hello

Apparently the file was already marked as executable by the linker which is what I would expect.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 5:21 pm

PabloMack wrote:pi@raspberrypi:~Apps $ ./hello
Inconsistency detected by ld.so: dl-lookup.c: 871 _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask nwords - 1)) == 0' failed!
pi@raspberrypi:~Apps $

I also did this and it didn't solve the problem (but it didn't complain):
pi@raspberrypi:~Apps $ sudo chmod +x hello

Apparently the file was already marked as executable by the linker which is what I would expect.
I didn't notice what was actually in the hello.c file. Did you post that? Did you delete and recreate the hello file using this code? Something is weird somewhere and it seems to go beyond permissions.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 5:29 pm

PabloMack wrote:This is what I did just now:
pi@raspberrypi:~Apps $ chmod 755 hello
pi@raspberrypi:~Apps $ ls -l
-rw-r--r-- 1 pi pi 0 Feb 28 16:09 save.txt
-rwxr-xr-x 1 pi pi 5976 Feb 28 16:00 hello
-rw------- 1 pi pi 5832 Feb 28 16:00 hello.a
-rw------- 1 pi pi 106 Feb 28 16:00 hello.c

pi@raspberrypi:~Apps $ ./hello
Inconsistency detected by ld.so: dl-lookup.c: 871 _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask nwords - 1)) == 0' failed!
pi@raspberrypi:~Apps $
That error message looks like what you'd get if you try running ld to make an executable and pass it an executable rather than object files and libraries. And having hello.a seems strange, .a is by convention a static library, not something you'd expect being used in a small single file program.

What exact commands did you do to compile?
She who travels light — forgot something.

PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 5:42 pm

> That error message looks like what you'd get if you try running ld to
> make an executable and pass it an executable rather than object
> files and libraries. And having hello.a seems strange, .a is by convention
> a static library, not something you'd expect being used in a small single
> file program.

Okay. I did this again and got the very same error:
$ gcc -o hello.o hello.c
$ ld -o hello hello.o
$ ./hello
Inconsistency detected by ld.so: dl-lookup.c: 871 _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask nwords - 1)) == 0' failed!
$

This is what is in the hello.c file:

#include <stdio.h>
main()
{
printf("Hello World!");
}

But now I'm even unhappier because in the previous install I loaded some fonts
and they were showing up in my application but now they are not after reinstalling
the OS to solve this problem even after I copied them to /usr/local/share/fonts and
set the file attributes to 644.

I have the fonts problem solved. Now I just need to be able to run programs that
were created with gcc and ld.
Last edited by PabloMack on Sun Feb 28, 2016 6:21 pm, edited 1 time in total.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 6:02 pm

Yes, you've run ld on an executable. gcc automatically creates an executable unless you tell it not no. If you want gcc to create an object file you need to pass -c to it (that tells gcc to only go as far as producing an object file).

Code: Select all

gcc -c -o hello.o hello.c
She who travels light — forgot something.

PabloMack
Posts: 10
Joined: Tue Feb 09, 2016 11:30 pm

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 6:24 pm

> gcc -c -o hello.o hello.c

Okay. Most compilers will compile to object then you have to use the linker
to build the executable. I'm not a fan of GCC and you can see why. All other
tool-chains I've ever used would have told me I am doing something wrong
because it would have known that the input file was wrong. GGC just let's
you do the wrong thing with no complaints.

This solved my problem and your help is much appreciated.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: ./ProgramName results in "Permission denied"

Sun Feb 28, 2016 6:43 pm

PabloMack wrote:Most compilers will compile to object then you have to use the linker.
Which modern compiler does that???
Had you just done:

Code: Select all

gcc -o hello hello.c
then

Code: Select all

./hello
it would have worked fine. By default GCC does the link for you.
As previously mentioned use gcc -c (-c means compile only) if for some obscure reason you need to call the linker by hand - which is VERY RARELY necessary for simple projects. A more complex example might be:
gcc file1.c file2.c file3.s -o prog -lmylib1 -lmylib2
which compiles or assembles the three source files, then links the three object files with the two libraries and produces a single executable called "prog".
Pi4 8GB running PIOS64

Return to “Beginners”