Compilation, Libraries and the pesky "unresolved external symbol" error
Вставка
- Опубліковано 1 тра 2023
- Understanding the Compilation Process is very important for anybody trying to get into compiled languages like C, C++, Rust, etc.
This is a video highlighting how this process works.
We start by going over the linker, symbols and object files, and using this as context for understanding different types of libraries: Static and Dynamic.
Discord: / discord
Relevant Links:
Just google it LUL.
(But really you'd get a lot better resources from googling than this video probably)
#C #C++ #Compilation
#MadeWithMotionCanvas
Back when I was learning C++, I wanted to use a library (SDL) to try make a game. I fell down such a deep rabbit hole of just tools like CMake and how you can compile that library yourself if you want. It was confusing but figured it out eventually.
This video is a great example on how the code eventually becomes .exe files. I love seeing that in action. Pretty cool.
I deeply admire these intricately constructed videos that thoroughly delve into and explain concepts down to their core. Thanks :D
Every library i've ever used in C, had me on a stump because of linking problems.
Videos like these are worth their length in gold.
Thank you sooo much for such a clear and concise explanation.
A possibly interesting side-note here is that you can use `ar` to store the main() function in a library and generate a binary without passing any object files or source files to the compiler. Another possibly interesting side-note is that on Linux a Shared Object (.so file sort of like a .dll on Windows), can have a main and be called like a regular program as well, and there are some use cases for that.
As for the first part talking about the difference between interpretation and compilation, in general every language can be dealt with in either way. Python can be compiled to a machine readable binary format, and it often gives a speed boost, but even languages like C could be interpreted if one felt so inclined to write an interpreter. I think the biggest stumbling block between switching back and forth is down to how much reflection a language has as well as how much the compiler does. C doesn't have to separate the preprocessor from the compiler, or for that matter the linker too, it just makes some really fantastic things easier to do.
Thanks for this video. Very underappreciated effort.
It shows how things look nice and tidy at the beginning with C and get really weird and complicated at the end with ugly compiler commands, macros, preprocessors etc. :)
Thanks for the detailed video. This helps me toward my goal of being strong in the fundamentals.
Great content! I'll be back for more!
I love your videos!
Well.. Windows is Special here xD The DllMain Function is an optional symbol, but if declared it has to be declared as DllMain in _stdcall (like any Pascal or Windows API function convention). The reason is especially backward compitblity reasons, since you could load ANY DLL into the global Space with AppInit_DLLs. You can still load DLL's with it into the Global Space, but you have to run Windows 7, disable Secureboot or having a certificate from Microsoft.
You can also just create a Driver and hook this function from there, but it also has to be loaded from a certificated Driver, which is easier in any case, than getting a certificate
This is a great channel, I really like the way you speak, very calm and informative, thank you for these videos, I really like C!!!
I wanted to ask, are you working currently anywhere or are you a student, would you ever find a job in C like embedded or similar and in which software do you make your videos? I'm asking because I want to find a job in C, but seems it is not a safe route...
I am a student yes. And I'm not an "only c" person. If I find a job that expects C knowledge I'd take it in a heartbeat, but if I don't, I still have other experience in other languages.
I make videos using motion canvas.
@@voxelrifts Thank you for the reply and keep up the good work!!!
Awesome
W + I like the person who says I guy at the start
Nice one! What do you use to make the animations / edit your videos btw?
I use motion canvas and Da Vinci resolve :)
Hey I know this is quite irrelevant but, since you're programming on Windows, I've been meaning to ask: what do you think about Makefiles, and make in general? I mean, to "automatically" compile and link many files (of a big project) with a single command, and/or to install a library or application from source. I've always wondered how C programmers on Windows go about it. Do you just replace it all with the static library files .lib/.a and the dynamic library files .dll/.so stuff? Or do you use something like CMake?
I see you even got clang and the ls command, which aren't usually on Windows... did you get them from Cygwin or MSYS2 or something else? Any recommendations?
Thank you sooo much for making this video, by the way! I find it very helpful!
I'm sure makefiles are super nice to use on linux, but since they're not super nice to use on windows I don't use them at all. Instead I use batch/shell scripts for building projects since I control everything that happens in them easily.
Clang can be easily installed on windows from the llvm github page whereas ls is just an alias that powershell provided there. So no msys or cygwin required :)
@3:22 Isn't a translation unit typically the output of the preprocessor, often with a .i or .ii extension, rather than the compiler?
Well technically a .i file is just a way to look at what is included in a certain translation unit, at a source level.
@@voxelrifts oh i see! thanks for the clarification.
How about you make a video about Cmake and linking
I'm afraid I'm not very familiar with cmake :P
:)
16:30 C you next time ☠️
Is missing to explain how do you find the symbols saved in the header, the lib or the os files"... Equivalent problem of knowing where the header files are located and how to list them.
⭐⭐⭐
You can just open the header files and look at their symbols. And a well documented library has some sort of documentation where all symbols are explained. Editors will even auto suggest you the symbols when you included the header files.
Also aren't the header files usually included in the Library zip? and os headers are usually in a documented folder that is automatically included by compilers.