In 54 Minutes, Understand the whole C and C++ compilation process

Поделиться
HTML-код
  • Опубликовано: 1 июн 2024
  • ►C++ Series Playlist: • The C++ Programming La...
    ►Find full courses on: courses.mshah.io/
    ►Join as Member to Support the channel: / @mikeshah
    ►Lesson Description: I've seen enough folks struggle with compiling in C and C++ that it is time for a full video to understand the process. As a result of understanding the compilation process, you can understand why a project should be split into smaller components, and how that makes your code faster to compile, easier to debug, and dare I say...more fun to work with!
    0:00 Introduction
    0:35 High Level Overview of Compilation
    6:17 Simple Project Setup
    10:10 Compiling
    12:09 Preprocessor output
    13:29 All functions are extern
    14:02 Syntax error versus linking error
    15:33 successful compile of multiple sources
    17:02 Redefinition errors
    18:30 Header Guards
    20:20 Compiler at a high level
    22:57 g++ syntax tree visualization
    24:53 Assembly Overview and Output
    28:24 Outputting object file (.o)
    30:00 Compiling Files Individually
    31:10 Linking o files together
    32:05 objdump
    34:22 Dynamically linked libraries
    35:30 ldd dynamially linked shared libraries
    36:35 Summary and Recap
    39:36 Practical Example with SFML Library
    40:45 Compiling without linking libraries error
    41:54 Linking in the correct libraries
    43:16 Using the -L flag to find library
    44:42 PATH and environment variables for default search paths
    45:58 Include Path
    50:00 Fixing Include Path Errors
    51:07 What your IDE is hiding from you.
    ►RUclips Channel: / mikeshah
    ►Please like and subscribe to help the channel!
    ►Join our free community: courses.mshah.io/communities/...
  • НаукаНаука

Комментарии • 122

  • @yanfranca8382
    @yanfranca8382 6 месяцев назад +5

    boy i wish i had seen this video when I was an undergrad

    • @MikeShah
      @MikeShah  6 месяцев назад +1

      Cheers! Yes, I show to all of my students -- it's essential knowledge in my book!

  • @jovannyswicktutorials9960
    @jovannyswicktutorials9960 3 дня назад +1

    This is special and deserves more views and likes. Well explained.

    • @MikeShah
      @MikeShah  3 дня назад

      Cheers, thank you!

  • @lucassilveira6449
    @lucassilveira6449 10 месяцев назад +18

    That was the best lecture about compilers on the whole internet. Thanks Mike!

    • @MikeShah
      @MikeShah  10 месяцев назад

      Cheers, thank you for the kind words!

    • @jorik170
      @jorik170 3 месяца назад

      couldn't agree more

  • @kjollyman241
    @kjollyman241 3 года назад +9

    I still watch these even after graduating 😅 thank you for the hard work!

    • @MikeShah
      @MikeShah  3 года назад

      Thanks Kraig! Th plan is to keep making and releasing more publicly! Now that you've been out working for a bit, we'll have to have you come back as a guest speaker for Fall 2021 FSE course :)

  • @olegwizex588
    @olegwizex588 2 года назад +3

    Thank you! Great video and explanation.

  • @min-yenlu1119
    @min-yenlu1119 2 года назад +1

    This is a really great video!!! I hope that I could see it when I started learning programming....
    This contains everything you need to learn for compiling process....
    It would have spared lots of wasted time.

  • @ashkrish7537
    @ashkrish7537 2 года назад +1

    Great content professor. 🙏🏻🙏🏻✌🏻✌🏻

  • @tamajitbanerjee640
    @tamajitbanerjee640 2 года назад

    Thank you, sir !! The content was very good.

  • @lln6123
    @lln6123 2 дня назад +1

    great explanation! Nice to see a Linux command-line approach, since now I just saw Visual Studio

  • @oscarmvl
    @oscarmvl Год назад +6

    What a great video! It was great to find such a cohesive video about the compiling process, thank you for creating this!

    • @MikeShah
      @MikeShah  Год назад +1

      You are most welcome!

  • @saberlite8809
    @saberlite8809 Год назад +5

    Impeccable explanation. I wish my college had professors like you who would explain the nitty gritty details and not just go through presentation slides.

    • @MikeShah
      @MikeShah  Год назад +1

      Cheers, thank you for the kind words!

  • @zikangxiong6931
    @zikangxiong6931 Год назад +7

    This video gives quite a practical overview. Tools like ldd and those flags are really most frequently used in any meaningful projects. Only those who really use C/C++ can summarize it in such a concise but practical way!

    • @MikeShah
      @MikeShah  Год назад +1

      Thank you for the kind words 🙂 I try to make the videos I wish I had when learning such topics. Welcome to the community!

  • @hsociety428
    @hsociety428 Год назад +2

    Bro this channel is soo damn underrated-- you should have like billion views on this video and billion subscribers

    • @MikeShah
      @MikeShah  Год назад

      Thank you for the kind words! :) Feel free to share

  • @willianpessoa1011
    @willianpessoa1011 Месяц назад +1

    This video has been incredibly helpful to me. Thank you for sharing.
    I've been a subscriber to your channel for some time now. I stumbled upon it while researching Design Patterns (which I'm still trying to master), but this video greatly assisted me in completing a questionnaire for my Computer Science Coursea at UFRJ
    I genuinely appreciate your content and aspire to become a professional like you in the future.

    • @MikeShah
      @MikeShah  Месяц назад

      Cheers, thank you for the kind words! I'm very happy this helped!

  • @sabrinagschwendtner276
    @sabrinagschwendtner276 2 года назад +13

    Thank you for this video! It helped me understand a lot of concepts that I missed or that weren't even included in my lectures in the first place. I have my bachelor's exam in a little over a week, so I am currently trying to fill the gaps in my knowledge and you definitely helped me with that! :D

    • @MikeShah
      @MikeShah  2 года назад +1

      You're welcome! Please suggest if anything else remains unclear

  • @Passions
    @Passions 2 месяца назад +1

    I would have never failed CS if you were my professor!!!!

    • @MikeShah
      @MikeShah  2 месяца назад

      Cheers, that's very kind! Always time to learn more :)

  • @nikolasyo1383
    @nikolasyo1383 7 месяцев назад +1

    Nice Video!!! So many things make sense now. I tried to include SDL in my C++ project on windows some days ago. Sould have watched this video before. would have saved me a lot of trouble.

    • @MikeShah
      @MikeShah  7 месяцев назад

      Cheers, happy to have helped!

  • @DCKUR
    @DCKUR 2 года назад +2

    Very detailed, thanks for creating this video :)

    • @MikeShah
      @MikeShah  2 года назад

      Thank you for the kind words!

  • @DocteurZeuhl
    @DocteurZeuhl 8 месяцев назад +2

    Thank you so much for this video. It really helped me put together every piece of information I have gathered along the way so far, and already gave me ideas on how to solve the (pretty sophisticated) linking issues I am currently facing. Incredible video ❤

  • @wika96
    @wika96 Год назад +1

    Great video Mike. Thank you very much.

  • @user-sz9ul1yp7l
    @user-sz9ul1yp7l 3 месяца назад +1

    Thank you for making difficult things seem easy 😍

  • @samarthtandale9121
    @samarthtandale9121 2 месяца назад +1

    Thank you for the valuable lecture Sir!

    • @MikeShah
      @MikeShah  2 месяца назад +1

      Cheers, you are most welcome!

  • @oribuun
    @oribuun Год назад +1

    Thank you so much for this amazing tutorial!

    • @MikeShah
      @MikeShah  Год назад +1

      Cheers, you are most welcome!

  • @samdavepollard
    @samdavepollard Год назад

    Superb video. Super useful. Many Thanks for sharing your knowledge. Easy sub.
    As an old fart hobbyist, currently getting back into C++, I'm amazed how few C++ resources, be they books or online courses, cover this build stuff in any detail. It seems most of them want you installing Visual Studio etc on day one, then there's a bit of magic hand waving, assuring you that the IDE will take care of all these things, and I'm sure it will, but I do like to know what my tools are doing for me. Then I try to install raylib and I become painfully aware that I don't have a clue about building from the command line.
    Again, Many Thanks for sharing your knowledge. I really like your teaching style. I noticed you have series on C++ itself, and also SDL2. I have a feeling I may end up using SDL2 instead of raylib. :-)

    • @MikeShah
      @MikeShah  Год назад

      Cheers thank you for the kind words! I agree, knowing how the tools work is very important 🙂

  • @nicholasziglio
    @nicholasziglio Месяц назад +1

    Thanks, this was really informative and useful!

  • @trido3815
    @trido3815 6 месяцев назад +1

    Very good instructions. Thx.

    • @MikeShah
      @MikeShah  6 месяцев назад

      Thank you for the kind words!

  • @jfr644
    @jfr644 Месяц назад

    Thank you for the great explanation!
    The only thing that raised doubts was the $PATH variable. It seems, it only indicates the location of the programs binaries to be executed within the shell without specifying their full path, not the shared libraries paths (resolving them by g++ seems to be more complicated since it is not controlled only with environment variables). The whole idea is clear though

  • @startengine8838
    @startengine8838 Год назад +1

    Awesome video. Very well explained

    • @MikeShah
      @MikeShah  Год назад

      Cheers, thank you for the kind words!

  • @somenkumardas9839
    @somenkumardas9839 Год назад

    A very good video... Very much enjoyed the learning. Thank you for the video.

    • @MikeShah
      @MikeShah  Год назад

      Cheers, thank you for the kind words!

  • @dontbemadsunshine
    @dontbemadsunshine 2 года назад +2

    This is awesome. Im doing a masters in a.i. next year and we will be having to use a lot of different languages throughout the course, i thought learning c/c++ would be advantageous as my first language. Thanks you very much for this!

    • @MikeShah
      @MikeShah  2 года назад +2

      Awesome glad this was helpful! Good luck with your master's!

  • @kacperkrol4394
    @kacperkrol4394 7 месяцев назад +1

    Great work!

    • @MikeShah
      @MikeShah  7 месяцев назад

      Thank you! Cheers!

  • @310gowthamsagar5
    @310gowthamsagar5 3 месяца назад +1

    this is great !

  • @ieduardoms
    @ieduardoms Год назад

    Thank you very much. It was really valuable.

  • @pabloqp7929
    @pabloqp7929 Год назад +1

    omg how good is this 🔥💫🌿

  • @peyman_shabani
    @peyman_shabani 6 месяцев назад +1

    Thanks Mike it was really great, I watched whole video non stop❤😅

    • @MikeShah
      @MikeShah  6 месяцев назад

      Excellent!

  • @stuartedward2965
    @stuartedward2965 Год назад +1

    very helpful! thank you

  • @Kirmo13
    @Kirmo13 8 месяцев назад +1

    I've never thought of using gimp as a whiteboard!

  • @saivivekvalluru1369
    @saivivekvalluru1369 8 месяцев назад +1

    Loved it! Really very useful info for c++ developer like me

  • @KeplerEmeritus
    @KeplerEmeritus Год назад +2

    Dude. Thanks. The most informative and comprehensive video I’ve found on the topic. Unfortunately, quenching this thirst gave me the hunger to dive deeper again… I want to see what assembled machine code looks like in the file… would we just see 1s and 0s?

    • @MikeShah
      @MikeShah  Год назад

      You are most welcome! Yes it's fun to see and know how it all comes together!

  • @NaveenKumar-cd8qh
    @NaveenKumar-cd8qh 2 года назад +1

    Nice explanation, keep doing best 🙂

    • @MikeShah
      @MikeShah  2 года назад

      Thank you for the kind words!

  • @Ab_Irato
    @Ab_Irato Месяц назад +1

    Hey Mike, bit of weird question but is there a reason to use gcc -E foo.cpp over cpp foo.cpp, i sort of understood the nont traditional mode in gnu but would sort of like your take on it.

    • @MikeShah
      @MikeShah  Месяц назад

      As I understand, I *think* 'gcc -E' is just invoking or rather telling the compiler to stop after running 'cpp'

  • @webcamdiary
    @webcamdiary Год назад +1

    Thanks a bunch!

  • @englishlnowledge486
    @englishlnowledge486 4 месяца назад +1

    Most underrated channel, Such explanation not able to find on other youtube channel or even paid courses, Have you provide your course on udemy???
    Thank You!

    • @MikeShah
      @MikeShah  4 месяца назад

      Cheers, thank you for the kind words 🙂 I have some courses here: courses.mshah.io/ -- I *may* consider also putting them on Udemy in the future

  • @creator_wizard_seth
    @creator_wizard_seth Год назад +1

    youre a genius

    • @MikeShah
      @MikeShah  Год назад

      Cheers, thank you for the kind words!

  • @mostafaelgablawy164
    @mostafaelgablawy164 2 года назад +2

    thank you sir that's a great vedio I have ever seen about compilations

    • @MikeShah
      @MikeShah  2 года назад +1

      You are most welcome!

    • @mostafaelgablawy164
      @mostafaelgablawy164 2 года назад

      @@MikeShah please I have a question when we include more times in several obj files what we had include exactly I found all the functions of iostream in every obj file I thought that I will get a linker error but that wasn't happen

    • @MikeShah
      @MikeShah  2 года назад +1

      @@mostafaelgablawy164 You mean none of the functions have been found? When you #include then you gain access to each of the functions (iostream provides the declarations in the header file). The appropriate libstd++ libraries will then be linked by the linker to implement those functions (e.g, std::cout)

    • @mostafaelgablawy164
      @mostafaelgablawy164 2 года назад +1

      @@MikeShah thank you so much

  • @r00ty
    @r00ty 8 месяцев назад +3

    so, just to avoid confusions please note nowadays (2023) - it's not really true that compiler outputs assembly code. GCC is the exception tho clang/LLVM, MSVC, and ICC all produce machine code directly

    • @MikeShah
      @MikeShah  8 месяцев назад +1

      Source? I imagine most every optimizing compiler would be building an intermediate representation that is 'assembly-like' (LLVM it is bitcode or IR, gcc GIMPLE), and then generating machine code (assembly) after. Probably true if you've got the assembly you would just directly generate the object file (or maybe the executable object file if they wanted) -- but I'd be curious to learn more.

    • @r00ty
      @r00ty 8 месяцев назад +1

      hey@@MikeShah , did you delete my response?

    • @MikeShah
      @MikeShah  8 месяцев назад +2

      @@r00ty Nope, sorry if it got lost! Sometimes RUclips deleted perfectly fine comments 🤷

  • @EarlyBitcoiner
    @EarlyBitcoiner Год назад +1

    Very good explenation! thank you! I start wondering now, what is the exe file and how it works?

    • @MikeShah
      @MikeShah  Год назад

      Cheers! Take a look at pe and elf formats 🙂

  • @muhammetkocak6903
    @muhammetkocak6903 3 месяца назад +1

    I hope you make video series about makefile and cmake

    • @MikeShah
      @MikeShah  3 месяца назад

      Cheers, I am thinking more about this :)

    • @muhammetkocak6903
      @muhammetkocak6903 3 месяца назад +1

      @@MikeShah I saw you C++ course and I will dive into it soon. I like your teacing fluency and sound. this is important for me

    • @MikeShah
      @MikeShah  3 месяца назад

      Cheers -- thank you for the kind words!@@muhammetkocak6903

  • @peyman_shabani
    @peyman_shabani 6 месяцев назад

    Mike could you please record some videos about Make or CMake, it will be great. 😊❤

    • @MikeShah
      @MikeShah  6 месяцев назад

      Starting to plan something for Make. 👍

  • @yashdeshmukh2662
    @yashdeshmukh2662 Год назад +1

    thanks

    • @MikeShah
      @MikeShah  Год назад +1

      Cheers, you are most welcome!

  • @user-ul2mr7cy3f
    @user-ul2mr7cy3f 5 месяцев назад +1

    Thank you for this tutorial. Please open terminal in full screen next time, drawings does not fit in half screen anyway.

  • @coolwinder
    @coolwinder 12 дней назад +1

    29:29 - If you are not providing an -c, which would enable valid gcc run, without a need of full source file, as onlt object file will be produced... Why are you naming the output which would now be an executable with .o extension?

    • @MikeShah
      @MikeShah  11 дней назад +1

      At 29:58 I mention that indeed this does not make sense to do :) I'm slowly introducing the idea of executable object files versus regular object files that can be linked together.

    • @coolwinder
      @coolwinder 11 дней назад +1

      @@MikeShah executable object, wuut, i am in suspece now... will there be another part?

    • @MikeShah
      @MikeShah  11 дней назад +1

      @@coolwinder I will indeed 🙂 There's actually (at least) 3 types of object files -- shareable, executable, and the static files with .o. We just call them by different names, but they're all 'object' files

    • @coolwinder
      @coolwinder 11 дней назад +1

      @MikeShah i can't wait then! Truly amazing content! :)

    • @MikeShah
      @MikeShah  11 дней назад +1

      Cheers ​@@coolwinder

  • @Warmess
    @Warmess 5 месяцев назад +2

    We got the same last name ,mine is Shah too. Meet Shah

    • @MikeShah
      @MikeShah  5 месяцев назад

      Excellent!

  • @azeemali6865
    @azeemali6865 Месяц назад +1

    Command 'xdot' not found

    • @MikeShah
      @MikeShah  Месяц назад +1

      What command did you run? 'xdot' is a program you can likely install on your package manager.

    • @azeemali6865
      @azeemali6865 Месяц назад +1

      @@MikeShah yes... After installing it's now working...

  • @edhermisaelcarbajalrosales1613
    @edhermisaelcarbajalrosales1613 8 месяцев назад

    tldr; Useful flags when compiling with gcc
    -E Preprocess only; do not compile, assemble or link.
    -S Compile only; do not assemble or link.
    -c Compile and assemble, but do not link.

  • @p.f.a.l.n.2280
    @p.f.a.l.n.2280 4 месяца назад

    Thank you! So nice to find informative videos like this without a thick accent to parse

  • @mnj1
    @mnj1 2 года назад +1

    Well, the Java or JavaScript way of doing things is completely different from C/C++, so your introduction is not completely accurate. JS is an interpreted language and Java is a language that relies on a virtual machine and intermediary language.

    • @MikeShah
      @MikeShah  2 года назад

      True that a interpreted languages and JIT compiled languages go through different variations (or even omit) some of the stages.

  • @Coding-to4zj
    @Coding-to4zj 3 месяца назад

    twisting simple concepts. do you have adhd? just write down what you want to talk about its so unefficient