13

How to make an object file to executable file?

Quonux
  • 2,975
  • 1
  • 24
  • 32
MalarN
  • 315
  • 3
  • 7
  • 20

3 Answers3

18

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
DrAl
  • 70,428
  • 10
  • 106
  • 108
4

If your file is a .o file that contains a main function you just need to link it, for example gcc file.o -o executable

Arkaitz Jimenez
  • 22,500
  • 11
  • 75
  • 105
0

Use the ld command. "ld file.o -o executable. This will give executable.