2.2.2. Compiling source files to object code
To create object code files from source files without creating an executable file immediately, instruct GCC to create only object code files as its output. This is a basic operation of the build process for larger projects.
Prerequisites
- C or C++ source code file(s)
- GCC installed on the system
Procedure
- At the command line, change to the directory containing the source code file(s).
Run
gccwith the-coption:$ gcc -c source.c another_source.cObject files are created, with their file names reflecting the original source code files:
source.cresults insource.o.注意With C++ source code, replace the
gcccommand withg++for convenient handling of C++ Standard Library dependencies.
Additional resources