Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating...
-
Upload
howard-joseph -
Category
Documents
-
view
215 -
download
0
Transcript of Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating...
![Page 1: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/1.jpg)
Compiling and Linking
![Page 2: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/2.jpg)
Compiling and Linking• Compiling is quite the same as creating an
executable file! Instead, creating an executable is a multistage process divided into two components: compilation and linking.
• In reality, even if a program "compiles fine" it might not actually work because of errors during the linking phase.
• The total process of going from source code files to an executable might better be referred to as a build.
![Page 3: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/3.jpg)
Compiling and Linking• Compilation• Compilation refers to the processing of source code files (.c, .cc,
or .cpp) and the creation of an 'object' file. • This step doesn't create anything the user can actually run. • Instead, the compiler merely produces the machine language
instructions that correspond to the source code file that was compiled.
• For instance, if you compile (but don't link) three separate files, you will have three object files created as output, each with the name <filename>.obj (the extension will depend on your compiler).
• Each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet! You need to turn them into executables your operating system can use. That's where the linker comes in.
![Page 4: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/4.jpg)
Compiling and Linking• Linking• Linking refers to the creation of a single executable file from
multiple object files. • In this step, it is common that the linker will complain about
undefined functions (commonly, main itself). • During compilation, if the compiler could not find the definition
for a particular function, it would just assume that the function was defined in another file.
• If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time.
• The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned.
![Page 5: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/5.jpg)
Compiling and Linking• Knowing the difference between the compilation
phase and the link phase can make it easier to hunt for bugs.
• Compiler errors are usually syntactic in nature -- a missing semicolon, an extra parenthesis.
• Linking errors usually have to do with missing or multiple definitions.
• If you get an error that a function or variable is defined multiple times from the linker, that's a good indication that the error is that two of your source code files have the same function or variable.
![Page 6: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/6.jpg)
Compiling and Linking
![Page 7: Compiling and Linking. Compiling is quite the same as creating an executable file! Instead, creating an executable is a multistage process divided into.](https://reader038.fdocuments.us/reader038/viewer/2022103123/56649d925503460f94a781cf/html5/thumbnails/7.jpg)
Compiling and Linking