tags:

views:

117

answers:

4

This might be the most newbie question ever, but how do you compile a C program?

I’ve downloaded the source of a C program (ffmpeg, to be precise). How do I compile it?

+4  A: 

For most Unix-style C programs, the incantation is:

./configure
make
sudo make install

This should already be documented in the INSTALL file, which additionally may contain further useful information.

Chris Jester-Young
Though to be fair, the actual compile command is probably `cc` or `gcc` and to compile a single file program it would probably look like `cc helloWorld.c`
FrustratedWithFormsDesigner
@Frustrated: That's true, but the OP didn't mean that. He meant "How do I build this project I downloaded?"
dmckee
Hopefully there is also a `make test` for the project. To be done before the install command.
Martin York
@Martin York: There is; the OP should have RTFM http://ffmpeg.org/documentation.html
Clifford
+1  A: 

It depends on what OS and compilers you have, but typically the sequence is:

$ ./configure
$ make
$ sudo make install
Paul R
+2  A: 

For a single file just cc file.c (or gcc or whatever you C compiler is called)

For a complex project like ffmpeg, then either make, cmake, configure some other. Check their documentation

Martin Beckett
+1  A: 

to compile simple math program, it's not enough to <include math.h>. See

gcc file.c -lmath -o program_bin

for a single .c file using ffmpeg libraries, it can be made this way:

gcc -Wall -g live_segmenter.c -o live_segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad -lpthread -I/home/devicer/ffmpeg/include -L/home/devicer/ffmpeg/lib 

notice -L and -I options. In serious projects they are usually set by pkg-config.

for the ffmpeg itself.. - install lame, few other required libraries, then do as Chris said. Btw, sometimes it requires gmake, not make.

Also, have a look on

./configure --prefix /home/devicer/ffmpeg

This is what was mentioned (used for) in segmenter compilation above.

mhambra