LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help in C programming in Linux (https://www.linuxquestions.org/questions/linux-newbie-8/help-in-c-programming-in-linux-564479/)

oliviapesayco 06-25-2007 09:15 PM

Help in C programming in Linux
 
Hi there.

I just wrote my first C prg in Linux (let's call it sample.c).... How can I compile it?

Thanks.

PatrickNew 06-25-2007 09:26 PM

try this:
Code:

gcc -o sample sample.c
it will call the ("gcc") compiler and instruct it ("-o sample") to build the program "sample" from the source code "sample.c".

oliviapesayco 06-25-2007 09:39 PM

Hi Patrick. I tried the gcc command you suggested, there are no errors and it built the program called sample. however, when I excute sample from the prompt it tells me that "sample: command not found"... I do not see the object file though, should it create a file called "sample.o"? Thanks.

dive 06-25-2007 09:46 PM

./sample

if you are in the same directory

oliviapesayco 06-25-2007 09:50 PM

Ok, that helped. thanks Dive
 
Ok, that helped. thanks Dive

dasy2k1 06-26-2007 08:04 AM

the reason that you dont see the .o files or all the other stuff usially created with a compiler is that GCC by default ether pipes output between processes or deletes the files afterwards,

if you need the filles for somthing there is an option to keep them

try man gcc for more details

timmeke 06-27-2007 05:19 AM

Code:

gcc -c ...
is for just compiling .c files into .o (no linking).

Code:

gcc -o prog ...
will compile the code if needed and then link it together into the program.
You can give both .c files (that will be compiled) and .o files
(previously compiled) as input for the linking.

Note that the "-o prog" is optional. If you don't specify the name of the output program that is to be created, it will be named "a.out" by default.

I suggest you read up on Makefiles and the "make" command too.


All times are GMT -5. The time now is 08:23 PM.