Learning about build system

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Learning about build system

Postby zazas321 » Sat Nov 19, 2022 11:12 am

Hello. I am learning about programming and how the source code is being turned into something that I can use to flash the microcontroller with.

Looking at the following image and going step by step:

Image

1. Code goes through preprocessor
2. Code goes through compilation. It is said that during compilation, the code is either turned into assembly code. Is this also true for C projects or the code is being turned straight into object code? Is it possible for me to look at the object code and see how it looks like? Looking at my project build folder, I cannot seem to find anything with .obj or .o extension


3. Code goes through linker after which the .bin project file is generated inside the build folder, is that correct?

I would appreciate if someone could help me understand and comment the process of building and preparing the code. Is assemblder required for all projects, if not, when it is required? Thanks in advance!

-+

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: Learning about build system

Postby vanBassum » Mon Nov 21, 2022 8:24 am

Preprosessor:
Handles things like defines, marcros, ifdefs ect.

Compiler:
Converts C code to assembly code.

Assembler:
Converts assembly code to binary data that the processor can use.

Linker:
The implementations in C, functions etc, are all separate pieces of code. The linker takes all these pieces and puts them together into one large BIN file.

Note that this isn't specific to ESP. This is how code compilation works for almost everything.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: Learning about build system

Postby zazas321 » Wed Nov 23, 2022 6:40 pm

vanBassum wrote:
Mon Nov 21, 2022 8:24 am
Preprosessor:
Handles things like defines, marcros, ifdefs ect.

Compiler:
Converts C code to assembly code.

Assembler:
Converts assembly code to binary data that the processor can use.

Linker:
The implementations in C, functions etc, are all separate pieces of code. The linker takes all these pieces and puts them together into one large BIN file.

Note that this isn't specific to ESP. This is how code compilation works for almost everything.

Thanks for reply! Could you clarify the following:

I was under the impression that if the code is written in C/C++ or other simillar mid/high level language, the compiler converts code straight to binary data (the assembler is skipped). Is that not right?

I thought that if the code is written in assembly, then the compiler is not being used, instead it goes through assembler and then linker


Specifically for ESP projects:
Can I find assembly code or binary code somewhere in the build directory or it is hidden from the user and you can only see the final .bin file?

vanBassum
Posts: 68
Joined: Sun Jan 17, 2021 11:59 am

Re: Learning about build system

Postby vanBassum » Mon Nov 28, 2022 8:09 am

Let me start by saying that I only know the general theory that compilation works. There could be differences in the way specific compilers work. If you want to know this, you have to read the documentation of the compiler.

Most tooling I have used have an option to show the resulting assembly code. But it might be that these files are only generated with a specific flag. There isn't much difference between asm and obj code, asm is just more human-readable.


"I was under the impression that if the code is written in C/C++ or other simillar mid/high level language, the compiler converts code straight to binary data (the assembler is skipped). Is that not right?" I'm not sure, you will have to read the documentation of the compiler.

"I thought that if the code is written in assembly, then the compiler is not being used, instead it goes through assembler and then linker"
Sure, if there is no code, there is nothing to compile to asm.

"Specifically for ESP projects:
Can I find assembly code or binary code somewhere in the build directory or it is hidden from the user and you can only see the final .bin file?"
The obj files can be found in buildfolder/esp-idf/main
I'm not sure if asm files are generated, and later deleted or not generated at all. I would assume there is a flag for this.

Who is online

Users browsing this forum: No registered users and 102 guests