How to make an executable file from a c object file?

MalarN picture MalarN · Dec 4, 2009 · Viewed 31.4k times · Source

How to make an object file to executable file?

Answer

DrAl picture DrAl · Dec 4, 2009

You need to link the object file. Your command:

gcc -c -o file.cgi file.c

compiles file.c into an object file (which would typically be called file.o). If you get rid of the '-c', it will generate the executable directly:

gcc -o file.cgi file.c

Alternatively (more useful if you have multiple files and don't want to compile all files when only one has changed), do it in two steps:

# Compile only
gcc -c -o file.o file.c
gcc -c -o file2.o file2.c
# Link
gcc -o file.cgi file.o file2.o