make: gcc: Permission denied -- what?

Cpt Chuckles

New Member
Credits
147
henlo all

I am having a bit of trouble getting gcc to run via make. I discovered this problem while trying to install a ruby gem, which invokes make to build the extensions, and got the "make: gcc: Permission denied" error. I have since experimented with a C++ hello world project and then a C hello world project, only to find that make seems to be incapable of invoking gcc, even when it is perfectly able to invoke g++. very odd. here is what I am getting:

Bash:
[[email protected] ~/docs/c/hello_world]
$ ls
main.c  makefile
[[email protected] ~/docs/c/hello_world]
$ cat main.c
#include <stdio.h>

int main(int argc, char* argv[]) {
  printf("hello world\n");
  return 0;
}
[[email protected] ~/docs/c/hello_world]
$ cat makefile
build:
    @echo "compiling C program with GCC, not even G++"
    gcc -o thing main.c
[[email protected] ~/docs/c/hello_world]
$ make build
compiling C program with GCC, not even G++
gcc -o thing main.c
make: gcc: Permission denied
make: *** [makefile:3: build] Error 127
[[email protected] ~/docs/c/hello_world]
$ sudo make build
compiling C program with GCC, not even G++
gcc -o thing main.c
make: gcc: Permission denied
make: *** [makefile:3: build] Error 127
[[email protected] ~/docs/c/hello_world]
$ gcc -o thing main.c
[[email protected] ~/docs/c/hello_world]
$ ls
main.c  makefile  thing*
[[email protected] ~/docs/c/hello_world]
$ echo wtf
wtf
[[email protected] ~/docs/c/hello_world]
$
In this snippet you can see that i am perfectly able to invoke the gcc command myself, while make cannot.

In the following snippet, observe that make can invoke g++ without issue:
Bash:
[[email protected] ~/docs/c/hello_world]
$ cd ../../cpp/hello_world/
[[email protected] ~/docs/cpp/hello_world]
$ rm thing
[[email protected] ~/docs/cpp/hello_world]
$ ls
main.cpp  makefile
[[email protected] ~/docs/cpp/hello_world]
$ cat makefile
build:
    @echo "compiling"
    g++ -o thing main.cpp -std=c++17
[[email protected] ~/docs/cpp/hello_world]
$ make build
compiling
g++ -o thing main.cpp -std=c++17
[[email protected] ~/docs/cpp/hello_world]
$ ls
main.cpp  makefile  thing*
[[email protected] ~/docs/cpp/hello_world]
$ echo "g++ works"
g++ works
[[email protected] ~/docs/cpp/hello_world]
$
Here are the permissions on the relevant directories and binaries (tell me if you need more):
Bash:
[[email protected] ~/docs/c/hello_world]
$ ls -ld ~ ~/docs/c/hello_world /usr/sbin/gcc /usr/sbin/make / /usr
drwxr-xr-x 17 root    root       4096 Dec 23 17:04 //
drwx------ 28 grendel grendel    4096 Mar 17 17:55 /home/grendel/
drwxr-xr-x  2 grendel grendel    4096 Mar 17 17:58 /home/grendel/docs/c/hello_world/
drwxr-xr-x  9 root    root       4096 Dec 23 17:05 /usr/
-rwxr-xr-x  3 root    root    1133432 Mar 14 16:05 /usr/sbin/gcc*
-rwxr-xr-x  1 root    root     243200 Feb  3 08:46 /usr/sbin/make*
I really don't understand why make is having trouble invoking gcc. I've been asking around in IRC channels about this and I haven't got a solution yet.


EDIT: I have found a way to make it work. I have changed "gcc" in my makefile to "/usr/bin/gcc" and now it runs just fine.... It seems that having `which gcc` return "/usr/sbin/gcc" is some kind of problem. I'm running Artix linux, wherein /usr/sbin is a symlink to /usr/bin. Here are the permissions:
Bash:
[[email protected] ~/docs/c/hello_world]
$ ls -ld /usr/*bin /usr/*bin/gcc*
drwxr-xr-x 5 root root   77824 Mar 17 15:51 /usr/bin/
lrwxrwxrwx 1 root root       3 Nov 13 14:01 /usr/sbin -> bin/
-rwxr-xr-x 3 root root 1133432 Mar 14 16:05 /usr/bin/gcc*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/bin/gcc-ar*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/bin/gcc-nm*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/bin/gcc-ranlib*
-rwxr-xr-x 3 root root 1133432 Mar 14 16:05 /usr/sbin/gcc*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/sbin/gcc-ar*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/sbin/gcc-nm*
-rwxr-xr-x 2 root root   35312 Mar 14 16:05 /usr/sbin/gcc-ranlib*
I have no idea why /usr/sbin/gcc is causing trouble to make, but it is. It's also something that's going to continue being a problem for me because until `which gcc` points to /usr/bin/gcc, i will remain unable to install ruby gems, because their makefiles are calling gcc and not explicitly /usr/bin/gcc. :s


EDIT 2: It seems that calling "/usr/sbin/gcc" from within the makefile also works. Now I have no idea what's going on. Why do i need to call the full path for it to work? :c
 
Last edited:


Alexzee

Well-Known Member
Credits
4,257
The current version of gcc is 9.1.0.
Is that what version you're running at this time?

You could just use your command line utility (APT, Pacman or other) to install ruby gems through the konsole/terminal. Is ruby gems in the AUR?

If it's not called from the full path within the makefile the command line interprter probably won't be able to find the makefile. Many times I have run make and bash has returned makefile not found because I wasn't in the right directory.
 
Last edited:

JasKinasis

Well-Known Member
Credits
3,291
@Cpt Chuckles :
Your environment looks a little odd....
The fact that /usr/sbin/ is a sym-link to /usr/bin/ seems strange enough in itself.

On top of that - its permissions look completely wrong. Normally the permissions for /usr/sbin would be 755 - the same as other directories. NOT 777!

Also /usr/sbin/ and /usr/local/sbin/ should not appear in a normal users environment either. So if the command which gcc returns /usr/sbin/gcc as a path - that would also indicate that your environment is messed up too!

Nornally /sbin/ /usr/sbin/ and /usr/local/sbin/ should only be in the environment for root. Those paths shouldn't appear in a normal users environment settings at all.

Not sure what to suggest offhand!
 

Cpt Chuckles

New Member
Credits
147
The current version of gcc is 9.1.0.
I have 9.3.0-1
Bash:
[[email protected] ~/docs/c/hello_world]
 $ gcc --version
gcc (Artix Linux 9.3.0-1) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You could just use your command line utility (APT, Pacman or other) to install ruby gems through the konsole/terminal.
I don't know about doing that, since I installed ruby using rbenv so I wouldn't have to install gems as root, which used to be working fine but now I have this problem with make not being able to invoke gcc :s

@JasKinasis I have been told by others that /usr/sbin should be a root thing, but I am running Artix Linux which is based on Arch Linux, which follows:
Arch Linux wiki said:
the file system hierarchy for operating systems using the systemd service manager
(even though my installation of Artix uses runit instead of systemd). Being a symlink I then don't think that the results of `which gcc` pointing to `usr/sbin/gcc` should be an issue, especially when writing out that full path in the makefile works. I'm just stumped when it comes to why i can't invoke just gcc from a makefile. It used to work just fine; I've installed gems before, but something must have broken since then.
 

Alexzee

Well-Known Member
Credits
4,257
I looked up rbenv-

Do you think that rbenv may have made it so that make can't be invoked by gcc?

Maybe start over again but this time find another method for getting ruby gems installed.
(just an idea)
 

Cpt Chuckles

New Member
Credits
147
@Alexzee I don't think rbenv is the issue... I actually have another computer with the same exact OS (Artix), WM, rbenv, Ruby, gcc, and make, all installed the same way, but on the other machine it works just fine.

This is also an issue I've had with trying to compile C programs (in this case, a hello world program) with make, and even simply invoking "gcc --version" in the makefile won't work. On my ThinkPad X1 Extreme 2, make always gives me the error "make: gcc: Permission denied", but everything works fine on my T420, and all the directories and permissions and versions of everything are identical on both machines. I'm really perplexed.
 

Alexzee

Well-Known Member
Credits
4,257
@Alexzee I don't think rbenv is the issue... I actually have another computer with the same exact OS (Artix), WM, rbenv, Ruby, gcc, and make, all installed the same way, but on the other machine it works just fine.

This is also an issue I've had with trying to compile C programs (in this case, a hello world program) with make, and even simply invoking "gcc --version" in the makefile won't work. On my ThinkPad X1 Extreme 2, make always gives me the error "make: gcc: Permission denied", but everything works fine on my T420, and all the directories and permissions and versions of everything are identical on both machines. I'm really perplexed.
Very odd situation you have going on. I'd be perplexed as well.

What if anything do you think is broken or misconfigured?
 

Cpt Chuckles

New Member
Credits
147
I'm clean out of ideas and I think I will just either reinstall my os on the X1 or just use the t420 until some updates come out, and hope that the process of installing the new version of make or gcc or kernel will magically fix it. :c
 

Alexzee

Well-Known Member
Credits
4,257
I'm clean out of ideas and I think I will just either reinstall my os on the X1 or just use the t420 until some updates come out, and hope that the process of installing the new version of make or gcc or kernel will magically fix it. :c
I haven't the faintest idea either, in fact, I think what is going on is really bizarre.

A fresh installation sounds like a good plan.
It's good that you have another machine that you can count on.

I've seen newer kernels fix things but I'm not sure if a newer kernel and updates would fix the make or gcc issue.
 

JasKinasis

Well-Known Member
Credits
3,291
I haven't the faintest idea either, in fact, I think what is going on is really bizarre.

A fresh installation sounds like a good plan.
It's good that you have another machine that you can count on.

I've seen newer kernels fix things but I'm not sure if a newer kernel and updates would fix the make or gcc issue.
Updates won't solve anything because the issue isn't with gcc or the kernel - the issue is with the users environment, which appears to be slightly borked. I've never seen this kind of problem before, so I'm not sure what to suggest to fix it.
 

Cpt Chuckles

New Member
Credits
147
I rebooted and now it works. ¯\_༼ ಥ ‿ ಥ ༽_/¯

No idea why or what's actually different, because I had rebooted before. The only thing I know for sure is different is that I removed /usr/sbin from my PATH but only in ~/.profile (it's still in my PATH because of something else [and `which gcc` still returns "/usr/sbin/gcc" on this machine, as opposed to my T420]) and I also deleted my ~/.bash_profile (which contained nothing but some rust cargo paths that are also being added by something else) so..... idk, magic!
 

Alexzee

Well-Known Member
Credits
4,257
Updates won't solve anything because the issue isn't with gcc or the kernel - the issue is with the users environment, which appears to be slightly borked. I've never seen this kind of problem before, so I'm not sure what to suggest to fix it.
What would create the users environment to become unstable/borked?
 



Top