I am trying to exec a shell in C using the following code:
#include <unistd.h>
int main(){
char *name[2];
name[0] = "/bin/sh";
name[1] = NULL;
execve(name[0],name,NULL);
return(0);
}
To compile this, I am using the gcc -static flag:
gcc -static -o shell shell.c
However, I get the following error:
/bin/ld: cannot find -lc
So far, I have tried to run : ld -lc --verbose
and here's what I've found:
attempt to open /usr/x86_64-mageia-linux-gnu/lib64/libc.so failed
attempt to open /usr/x86_64-mageia-linux-gnu/lib64/libc.a failed
attempt to open /usr/local/lib64/libc.so failed
attempt to open /usr/local/lib64/libc.a failed
Can anyone please help me figure out what's going wrong here?
If you want to use -static, you need to install glibc-static-devel.