Тёмный
No video :(

Back to Basics: Compiling and Linking - Ben Saks - CppCon 2021 

CppCon
Подписаться 152 тыс.
Просмотров 48 тыс.
50% 1

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@RunningSwimmingMan
@RunningSwimmingMan 2 года назад
Finally someone with GOOD info, without the colossal attitude & ego! This kind of practical info is exactly why I watch these cpp videos. Thank you Ben!
@CppCon
@CppCon 2 года назад
Glad it was helpful!
@paoloose
@paoloose Год назад
these basics are that kind of information that changes the way you think about your code process. Thanks!
@CharlieScarver
@CharlieScarver 3 месяца назад
Finally an understandable and comprehensive explanation! Thank you for this presentation.
@SurfinScientist
@SurfinScientist Год назад
This video was hugely helpful for me. Thanks a lot!
@nothke
@nothke 2 года назад
This is such a great talk. I was really struggling to understand how headers, compilation units and linkers work when I was starting out with C++, and spent so much time dealing with these errors as my programs were growing and started cross-referencing everything in the project. Especially when coming from "easier" languages where all this is completely hidden from the user. This should be one of the first videos people should watch! One thing I felt missing from the talk is any mention of precompiled headers and what pros and cons they have. And also with all the stuff Ben flew past at the end I feel like this really needs a part 2 :)
@kamilziemian995
@kamilziemian995 Год назад
Great presentation. I learn a lot from watching it.
@CppCon
@CppCon Год назад
Glad it was helpful!
@jimwinchester339
@jimwinchester339 2 года назад
Good job. You had a lot of ground to cover there, and got through it quite admirably.
@PUZO37RS
@PUZO37RS Год назад
Cool talk with good material to start with! Thanks!
@vikaskumarsharma2322
@vikaskumarsharma2322 2 года назад
Extremally informative and great presentation. thank you for the efforts. Thank you Ben and CppCon.
@CppCon
@CppCon 2 года назад
Much appreciated!
@allyourcode
@allyourcode 2 года назад
@7:35 Maybe I'm misunderstanding what's going on here, but seems to me that the main reason not to define functions in header files is NOT that it slows the build process, but rather that it (almost always) BREAKS the build process, because it inevitably causes violations of the one definition rule down the line EVEN THOUGH you use #include guards. To see why such a violation would usually arise, imagine there is a library X that supplies function f. Furthermore, suppose libraries A and B use X. To do this, they would #include "x.h". You'll probably be able to compile A and B just fine (without violating ODR) thanks to #include guards, but if application K uses A and B, when you try to build K, the linker will see two "versions" (copies) of the definition of f floating around in the application. The fact that the two "versions" are exact copies of one another won't rescue you; the linker will still freak out on you, even though you could argue that it really doesn't need to, but not for some annoying rules of the language. The linker does not see that the original C++ definition of f exists only in one source code file (i.e. x.h), because that information does not get passed downstream from the preprocessor (and then further downstream by the compiler). All it knows is that two of the object files that are being fed in each contain a definition of f. You might ask "But why doesn't the linker just look at the code in those two definitions and notice that they are the same?". That's a sensible question, but it's possible that the two translations of f (one in A, the other in B) are different, even though they behave the same. There is no reliable way for the linker to detect that the two translations of f behave the same way, so we don't ask it to do that. Instead, we let the linker give up.
@David_Friberg
@David_Friberg 2 года назад
I assuming that Ben is answering this question under the prerequisite that we are considering the legal C++ domain. ODR-violations due to multiple definitions of non-inline functions is outside of the domain of legal C++. Indeed, a rule "always define your functions outside of source files" could help junior devs to coincidentally avoid ODR violations, but imho it's better to use education and tooling to teach and lint, respectively, the dos and don'ts of function definitions in headers (and beyond).
@mykhailomykytyn
@mykhailomykytyn 2 года назад
watching this alters the time run
@linuxgaminginfullhd60fps10
@linuxgaminginfullhd60fps10 2 года назад
Yeah, I knew about the problem of huge compilation times arising from the same stuff generated from the same template in multiple object file and then linker removing the duplicates. Now I see that apart from longer compile times it is also dangerous in some cases, because the linker just picks any definition and does not have to care if they are actually the same. And if it does care it would increase the compilation times even further. So it is quite easy to introduce some UB by accident. Defining explicit specializations and using extern in the header file fore them solves both issues. This is an obvious solution for an experienced dev, but still it needs to be seen at least once to understand that that's the way! Thanks for reminding us the basics and pointing out to this very common example, where things can be made better just with a little effort. I wonder if that's the reason chromium takes forever to compile with regular(non-jumbo) build on Linux.
@azdinator
@azdinator 5 месяцев назад
The slides of Ben Saks are not available on github. Is there any reason for that ?
@Cowboydjrobot
@Cowboydjrobot 2 года назад
Wow so helpful! Truly amazing
@CppCon
@CppCon Год назад
Glad it was helpful!
@muhammadharris4470
@muhammadharris4470 2 года назад
Ben love your Back To Basics videos are superb !! I wish we were taught like this :)
@CppCon
@CppCon 2 года назад
Glad you like them!
@colin398
@colin398 Год назад
This guy is very articulate and good at teaching
@DocteurZeuhl
@DocteurZeuhl 11 месяцев назад
Hi CppCon, the slides for this presentation are still not available to my knowledge (I just searched in the GitHub repo and could not find them), which is a shame as the remaining examples are probably very interesting too. Thanks in advance! (Great talk, by the way! Exactly what I needed right now, with a lot of information ❤)
@giveaway4002
@giveaway4002 11 месяцев назад
yes very true, i need those slides too
@azdinator
@azdinator 5 месяцев назад
Did you get the slides ? Can't find them
@la_ki
@la_ki 2 года назад
This guy is great tutor and funny to watch.
@leftunfounded885
@leftunfounded885 2 года назад
Linker scripts are a PITA. I usually have an idea of where RAM/Flash and abs addresses when i'm typing in the code source files. I don't want to write another obtuse file for linker obtuse statements. Some proprietary embedded compilers allows the "where" declarations in the source codes,so much better/cleaner.
@shameelgoldentrio2928
@shameelgoldentrio2928 Год назад
At 33:51, the function g was forward declared in b.o object file and defined in c.o. Is this acceptable? It doesn't have a extern keyword as well. If this is acceptable does the linker look for a particular function definition across all the available obj files before throwing undefined function error.
@berktopbas1496
@berktopbas1496 4 месяца назад
I must have misunderstood sth, cannot comprehend the second item on slide 37(37:50). How is it possible not violating *ODR* by just _"defining the entity in a single header that doesn't depend on including other headers"_ ? I test it in my MSVS with C++20 and get error. It is either possible using *inline* keyword denoting _the same entity_ for all translation units or *static* keyword for _different entities_ for each translation unit, afaik.
@stormingbob
@stormingbob Год назад
Where can I find the slides for this talk?
@KFlorent13
@KFlorent13 Год назад
For example at 18:10 I don't understand why int i; is a definition. To me it would be more logical that it's a declaration and that to be defined it should be int i = 12; for example. Is it because even though I did not assign a value to i I can still use it with its defauld garbage value ?
@colin398
@colin398 Год назад
See 10:57
@ahmadalastal5303
@ahmadalastal5303 11 месяцев назад
let me explain it in few words: Definition: memory will be allocated to it either by compiler(will make binary size bigger) or at runtime. Declaration: no memory is allocated for it yet. So for function/variable definitions: memory is allocated for code/variable at compile time and later in the binary.
@jason_liam
@jason_liam 2 года назад
Really Helpful Talk.
@chaicblack7415
@chaicblack7415 4 месяца назад
When I reading the C++ book, these template stuff cost me a lot of time.
@sudarshanrammurthy4714
@sudarshanrammurthy4714 2 года назад
Can you please link the presentation? Would like to see the slides that were missed in the end! Thanks!
@kacperkrol4394
@kacperkrol4394 2 года назад
Did you found the slides?
@MrM12LRV
@MrM12LRV 2 года назад
Nice one! :)
@peterevans6752
@peterevans6752 2 года назад
Good Refresher!
@LDdrums20
@LDdrums20 2 года назад
Imagine that household. They probably have classes for dinner 😂😂😂. Seriously though, great talk!
@bondymagnomous3544
@bondymagnomous3544 2 года назад
I wonder, why would anyone want to put certain function definitions into flash memory instead of RAM? Nice presentation btw.
@erkinalp
@erkinalp 2 года назад
Execute in place arrangement?
@didgishdtube2169
@didgishdtube2169 2 года назад
So the program (or parts of it) can survive a power-off/restart?
@robheusd
@robheusd 2 года назад
it was data, not code.
@GrantSR
@GrantSR 2 года назад
This guy is a "professional" trainer?
@kerem6680
@kerem6680 Год назад
i have a not good english and he is dither a lot in presentation. this makes hard to understanding.
Далее
why do header files even exist?
10:53
Просмотров 395 тыс.
Leslie Lamport: Thinking Above the Code
59:50
Просмотров 367 тыс.