|
Home > Archive > Unix Programming > January 2004 > Compile and Run
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]
|
|
| Shane Malden 2004-01-23, 5:16 pm |
| Hi, Can someone help me out.. After writting the code in c or c++ what
commands in RedHat do you use to compile the application? Once compiled do
you just run it as any other command? Any help is appreciated.
Regards,
Shane
| |
| Jens.Toerring@physik.fu-berlin.de 2004-01-23, 5:16 pm |
| Shane Malden <smalden@bigpond.net.au> wrote:quote:
> Hi, Can someone help me out.. After writting the code in c or c++ what
> commands in RedHat do you use to compile the application?
That's a bit difficult to tell because that might depend on which
libraries you need etc. But in the most simple case, when you have
a single source file that doesn't depend on any external libraries
(except the system library), it can be as easy as
make myprog
if the source file is named myprog.c or myprog.cpp. If you wnat to
invoke the compiler and linker directly instead of having the make
utility do the work for you you may just need
gcc -o myprog myprog.c
or
g++ -o myprog myprog.cpp
If you require math functions you have to add '-lm' to these lines.
Of course, all of the above assumes that you have 'make' and gcc
installed on your system.
quote:
> Once compiled do you just run it as any other command?
Yes. Just type './myprog' and it should be executed (depending on
how your system is set up you may even be able to drop the './' bit
at the start of the command).
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.physik.fu-berlin.de/~toerring
| |
| Master Web Surfer 2004-01-23, 5:16 pm |
| [This followup was posted to comp.unix.programmer]
In article <pBjAb.41861$aT.3617@news-server.bigpond.net.au>,
smalden@bigpond.net.au says...quote:
> Hi, Can someone help me out.. After writting the code in c or c++ what
> commands in RedHat do you use to compile the application? Once compiled do
> you just run it as any other command? Any help is appreciated.
>
> Regards,
> Shane
For a simple one file program that only uses standard UNIX libraries
you could do something like the following :
gcc mycommand.c -o mycommand
Then you run "mycommand" just like any other command.
If your program uses some other special libraries then you
could do something like the following :
gcc mycommand -o mycommand -llibname
| |
| =?iso-8859-1?q?M=E5ns_Rullg=E5rd?= 2004-01-23, 5:16 pm |
| Master Web Surfer <raisin@delete-this-trash.mts.net> writes:
quote:
>
> For a simple one file program that only uses standard UNIX libraries
> you could do something like the following :
>
> gcc mycommand.c -o mycommand
Or, even simpler,
make mycommand
quote:
> Then you run "mycommand" just like any other command.
Depending on your $PATH, you might have to use ./mycommand, to run it
from the current directory. Having . in your PATH is a bad idea.
--
Måns Rullgård
mru@kth.se
|
|
|
|
|