LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Permission denied when compiling C program (https://www.linuxquestions.org/questions/programming-9/permission-denied-when-compiling-c-program-773026/)

mominmyheart 12-02-2009 01:40 PM

Permission denied when compiling C program
 
Hello:
I am writing a C program and trying to compile it under fedora9 when I type
gcc filename.c -o filename it suceeds but when I type ./filename.c it gives me Permission denied.
I am working in my code on threads basically using clone. Is there any relationship with this line
#define CLONE_VM 0x00000100

jschiwal 12-02-2009 01:42 PM

Did you type ./filename.c or ./filename? You would enter the latter to execute your program.

mominmyheart 12-02-2009 01:51 PM

I put ./filename.c first and it gave me permission denied but when I put ./filename it doesn't show anything. Does this mean there is certain problem in my code?

jschiwal 12-02-2009 01:56 PM

Probably. Your first command is trying to run the source code which is wrong. Sounds like it is debugging time.

GrapefruiTgirl 12-02-2009 01:59 PM

I don't have a clue what your program is supposed to do, but is it supposed to output anything (text?) to the screen when it executes? If not, then when you execute it, it will either run and exit silently, or run and exit with an error.

As for when you type ./filename.c you are in effect trying to execute a text file. "Permission denied" happens most likely because the file is not set with "execute" bit. If you do the command:

shell$ chmod a+x filename.c

then it will be executable, but there's no point; it won't run, because it's a .c source code file (a text file, not a shell executable or binary).

Like Jim mentioned above, your compiled binary should be called "filename"; that's what you want to execute after the source has been compiled.

Sasha

mominmyheart 12-02-2009 01:59 PM

Sorry but I didn't I understand what you mean?

mominmyheart 12-02-2009 02:10 PM

I think I got your point but the executable file has appeared on the desktop but no results. My program suppose to output certain lines.

GrapefruiTgirl 12-02-2009 04:49 PM

Well then, it sounds like your program does not work ;)

I am going to request a move of this thread, to the programming forum, where it may get better exposure to other programmers who might be able to offer advice.

Sasha

raju.mopidevi 12-02-2009 05:05 PM

I think you are using wrong command.

you can execute *.c file , so this command is wrong
Code:

$ ./filename.c
follow this commands
Code:

$  gcc -o filename filename.c
$  chmod 744 filename
$  ./filename

to know building C programs see this

pixellany 12-02-2009 05:08 PM

Quote:

Originally Posted by mominmyheart (Post 3777507)
I think I got your point but the executable file has appeared on the desktop but no results. My program suppose to output certain lines.

first, you have to compile. If that is successful, then you have to run the executable file.


All times are GMT -5. The time now is 02:19 PM.