How to make an object file to executable file?
An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable.
The best way to open an O file is to simply double-click it and let the default assoisated application open the file. If you are unable to open the file this way, it may be because you do not have the correct application associated with the extension to view or edit the O file.
Object file(.o): These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves and by convention their names end with .o. Binary executables file(.exe): These files are produced as the output of a program called a “linker“.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With