Home > Archive > Unix Programming > July 2006 > How to run a C program under linux ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to run a C program under linux ?
|
|
| ThaDoctor 2006-07-27, 4:00 am |
| Hi. How do I run my first C application under linux it is compiled I
just need the code to run the program.
Greetings Tobias
| |
| Russell Shaw 2006-07-27, 8:00 am |
| ThaDoctor wrote:
> Hi. How do I run my first C application under linux it is compiled I
> just need the code to run the program.
chmod u+x myprog
../myprog
| |
| Jim Cochrane 2006-07-27, 7:00 pm |
| On 2006-07-27, Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote:
> ThaDoctor wrote:
>
> chmod u+x myprog
>
> ./myprog
It needs to be executable before you can 'execute' it (which is what
the above chmod does). You can do a 'ls -l myprog' to check that it's
executable - e.g.:
cd /usr/bin
ls -l wc
-rwxr-xr-x 1 root root 24048 May 25 2005 wc
The 3 'x's, from left to right, mean that it is executable by the owner,
owning group, and everyone else, respectively. So if you want everyone to
be able to execute it (which is often the case), you can do:
chmod 755 myprog
or
chmod +x myprog
--
| |
| Pascal Bourguignon 2006-07-27, 7:00 pm |
| "ThaDoctor" <Tobias.Skak@gmail.com> writes:
> Hi. How do I run my first C application under linux it is compiled I
> just need the code to run the program.
What did you wrong? How did you compile it?
Normally, gcc or ld set the executable permissions on their output.
What is your umask?
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Specifications are for the weak and timid!"
| |
| Gordon Burditt 2006-07-27, 7:00 pm |
| >>> Hi. How do I run my first C application under linux it is compiled I
I haven't encountered a compiler for a UNIX-like system that doesn't
set executable permissions on the compiled program if it compiled
without errors (with the distinction between "error" and "warning"
being compiler-specific). The user who just compiled it should be
able to run it without a chmod. On the other hand, if you have a
restrictive umask but want everyone to be able to run the program,
this is useful.
[color=darkred]
Using the ./ prefix is particularly critical if you call your
program "test" and /bin/test is found in the $PATH search before
or instead of your program.
[color=darkred]
>It needs to be executable before you can 'execute' it (which is what
>the above chmod does). You can do a 'ls -l myprog' to check that it's
>executable - e.g.:
>
>cd /usr/bin
>ls -l wc
>
>-rwxr-xr-x 1 root root 24048 May 25 2005 wc
>
>The 3 'x's, from left to right, mean that it is executable by the owner,
>owning group, and everyone else, respectively. So if you want everyone to
>be able to execute it (which is often the case), you can do:
>
>chmod 755 myprog
>
> or
>
>chmod +x myprog
| |
| Chris F.A. Johnson 2006-07-27, 9:59 pm |
| On 2006-07-27, ThaDoctor wrote:
> Hi. How do I run my first C application under linux it is compiled I
> just need the code to run the program.
Type the name of the program you compiled.
If it is not in a directory on your PATH, you also have to use the
path to the file, e.g. ./my_first_C_prog
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Bruintje Beer 2006-07-28, 4:00 am |
|
"ThaDoctor" <Tobias.Skak@gmail.com> schreef in bericht
news:1153994238.216874.65210@i3g2000cwc.googlegroups.com...
> Hi. How do I run my first C application under linux it is compiled I
> just need the code to run the program.
>
> Greetings Tobias
>
Hi
if you compile and link a c program under unix the output will be standard
a.out unless you specify the name of the program with the -o option for your
compiler
examples
gcc hello.c will generate a.out which you can run from the shell
gcc -o hello hello.c generates the program hello.
Johan
|
|
|
|
|