views:

147

answers:

3

Related to this question. What's the process for compiling a C program (assume 1 file)?

+6  A: 

Quoting http://users.actcom.co.il/~choo/lupg/tutorials/c-on-unix/c-on-unix.html:

The easiest case of compilation is when you have all your source code set in a single file.

cc single_main.c

You might complain that 'a.out' is a too generic name (where does it come from anyway? - well, that's a historical name, due to the usage of something called "a.out format" for programs compiled on older Unix systems). Suppose that you want the resulting program to be called "single_main". In that case, you could use the following line to compile it:

cc single_main.c -o single_main 
The MYYN
"cc"? Are we in the 50s?
Andreas Bonini
well, nowadays it usually will be a symlink, i guess ..
The MYYN
on FreeBSD, `/usr/bin/cc` is the same file as `/usr/bin/gcc`, and `/usr/bin/c++` is the same file as `/usr/bin/g++` (hardlinks). FreeBSD 8 ships with `(GCC) 4.2.1 20070719`
just somebody
+5  A: 

It depends on what compiler/IDE you use.

With Visual Studio ctrl-shift-B is all you need to build your project.

With gcc enter in the command line: gcc file.c -o executable_name.

Andreas Bonini
+1  A: 
NAME
       gcc - GNU project C and C++ compiler

SYNOPSIS
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-pedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

       Only the most useful options are listed here; see below for the remain-
       der.  g++ accepts mostly the same options as gcc.

DESCRIPTION
       When you invoke GCC, it normally does preprocessing, compilation,
       assembly and linking. [...]
just somebody