What does the ctr1.o object code file do in the gcc compiler?

What does the obj ctr1.o file do in the gcc compiler? Why does the linker link this obj file whenever an executable is generated?

+3
source share
3 answers

I think it contains a very simple stuf (crt means C runtime), like creating argv and argc for your main function, etc. Here is a link with some explanation

If you do not want this because you are writing a tiny bootloader, for example, without any libc bits, you can use the -no-stdlib options to link your program. If you go this route, you will also need to write your own script builder.

+6
source

Object files store your compiled code, but they themselves are not executed. The task of the linker is to take all the object files that make up the program and combine them into a whole. This includes resolving links between object files ( extern characters), checking for the main() entry point (for C programs), etc.

Since each source file (.c or .cpp) is compiled into a separate object file, which is then read by the linker, changes to one C file mean only what can be recompiled, create a new object file, which is then linked to existing object files in a new executable file. This speeds up development.

UPDATE: As indicated in another answer, the “crt.o” object files contain the C r un t code, which is considered necessary by most C programs. You can read the gcc linker options and find the --no-stdlib , this will tell gcc. that your particular program should not be associated with standard C.

+1
source

I am not sure to understand your question, but I think you mean "crt1.o" in the GCC package.

crt is one of the basic libc packages that provides basic functions for accessing a computer. IIRC contains methods such as "printf", etc.

This is why it is often even included in the most basic C applications.

+1
source

All Articles