How the C++ Linker Works

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

Linking is fun, but have you tried blinking? =))

totallynuts
Автор

This is the C++ explanation I've always wanted. Great series!

redoxepk
Автор

This series is great so far. One problem is a lot of teachers hold your hand so much and give too much detail on simple things, but others just skip over important details. The fact you go into detail of the why and explain how the compiler and linker works in a practical way is so helpful. I see myself going through this whole series.

KasperKenDev
Автор

Imagine if the linker was a human though.. what a horrible job.

Linker: Mate, seriously, for the fifth time today where is the multiply() function?
Me: Wha.., it's not there?
Linker: ...No
Me: Are you sure?
Linker: YES, I AM SURE!
Me: can't be, check again.
Linker: AGHRGR
Me: Ooops, accidentally typed it as mltply().. lol

jere
Автор

Short Summary:
After Compilation, we need to go through linking. linker finds each Symbol and Function and stitches them together to make an exe file. Multiple Obj files can’t interact with each other so if we have split our program into multiple C++ files they need a way of linking them together into a single exe file and this what essentially a Linker does.

Even if u don’t have multiple files linker still needs to link main function. It needs to know the starting point of your program. He gives example by creating a file that didn’t have the main function, this file compiled successfully however when linking it generated a linking error saying entry point not found.

There are different error types for Compilation and the linking stage in VS. It begins with C for compilation and LNK for Linker error. For example, a syntax error is a compilation error, and the main not found is a linker error.

As in project property, the config type is set to .exe file and every exe file must have an entry point we need to specify an entry point by default it is the main function. we can specify a custom entry point in linker > advanced > entry point

Then he explains about a specific type of Linker error called “Unresolved external Symbol”. This basically occurs when the linker can't find the specific symbol.

watch 6:58 can’t explain it in words. Writing static in front of a function implies that we’ll only use that function in that file only.

For the linker not only the function name is important but also the parameters and return must match 100%.

If you define the same function twice in the same file compiler will generate an error because the compiler works on one file and it can detect it. however, if you have the same function definition in multiple files the linker will generate an error because the linker doesn’t know whom to link to the call. This is the reason why we keep function declarations in .h file and not the whole definition because if we do so we can’t include that .h file in multiple files because that’ll generate linker errors.

drj
Автор

I love that you teach the concepts through errors, as it's all good and well understanding how something works, but understanding what breaks it is far more crucial in most cases. Thank you for this series. I'm aiming to learn C++ from a Java / C# background and finding it incredibly easy to grasp the differences with your guidance. Kudos!

mikc
Автор

This finally explain why we just declare things in a header file and only give one definition in cpp files, because that way the linker always find the right one when linking functions. And the #include just make that file knows the functions exist. I didn't get it since I started programming 2 years ago until now. Thank you so much.

cccccroge
Автор

The example with Log.h is fantastic, I had no idea such a thing could happen!

olestrohm
Автор

you're trying to teach all about C++ and I love it

ikergalardi
Автор

I have been programming for 7 years now and I learned a lot from this video.

matheus_olliric
Автор

I just started learning programming 2 weeks ago, and this is by far a really great explanation (of what happens behind the C++ scene) that can be understood by a total beginner. Thank you!

nerdmommy
Автор

This is the best C++ series on Youtube. Incredibly enlightening. Even though I studied C++ in college and have been using it at work for the past 3 years, I often miss the nuances of the compilation and the linking process. I feel like I am in college again!

shriram
Автор

Dear Cherno, I am amazed by how you manage to give us awesome tips and tricks even when covering "simple" concepts. such as linking. You truly inspire me to dig deeper into the language, IDE, everything. Keep doing an amazing job!

NinaTheLudaca
Автор

These videos are by far the best programming series on YouTube, I watched them a few years ago and find myself re-watching them after not touching C++ for a long time. Very well, thought out videos.

RoyMay
Автор

Really like your videos. You have the C++ language, CS theory, practical hands on stuff like how to optimize work with VS, experience from an actual professional, low level assembly and memory, all combined with a good presentation.

MsJavaWolf
Автор

Great series so far! I love how people of all skill levels can take something from these tutorials.

kemptcode
Автор

Somehow landed back here in 2023 and this still is the best c++ series out there. People mostly want to learn c++ to get a job but neve want to know the in depth version of it's working. There is no limit to human stupidity.
@The Cherno You are awesome!!
I hope I can contribute to hazel in a couple of months!!

HungryEagle
Автор

Now this is what i call worth watching tutorials! You explained SO MUCH to me! Thank you! Now i understand how libraries are included like 'inline style', how and when Linker works, and that i can put whole definitions into header files (which of course is not a good practice). You make great job not only for beginners but for everyone who on some level missed some knowledge. Yours is awesome. Keep goin' and one again GREATEST THANK YOU CHERNO!!!

MacKMir
Автор

I can't thank you enough for this series, the amount of knowledge you are able to deliver in 15-20 mins about one topic is just amazing to say the least. At the starting I found it a little bit fast but now I am able to keep up with the pace.

twitchoff
Автор

This is a great series. I really love the way on how you are showing things practically instead of just saying it out and also giving example of error that programmers do. It really helps understand the concept well and combine them.

sarvottammodi