简体   繁体   中英

How easy is compiling a C program?

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

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 

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 .

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. [...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM