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

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 มิ.ย. 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.
    ►TH-cam Channel: / mikeshah
    ►Please like and subscribe to help the channel!
    ►Join our free community: courses.mshah.io/communities/...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 135

  • @lucassilveira6449
    @lucassilveira6449 10 หลายเดือนก่อน +19

    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

  • @yanfranca8382
    @yanfranca8382 7 หลายเดือนก่อน +6

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

    • @MikeShah
      @MikeShah  7 หลายเดือนก่อน +3

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

  • @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 ปีที่แล้ว +4

    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.

  • @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  ปีที่แล้ว +2

      Cheers, thank you for the kind words!

  • @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!

  • @zikangxiong6931
    @zikangxiong6931 2 ปีที่แล้ว +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  2 ปีที่แล้ว +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!

  • @jovannyswicktutorials9960
    @jovannyswicktutorials9960 22 วันที่ผ่านมา +1

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

    • @MikeShah
      @MikeShah  22 วันที่ผ่านมา

      Cheers, thank you!

  • @tamajitbanerjee640
    @tamajitbanerjee640 2 ปีที่แล้ว

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

  • @ashkrish7537
    @ashkrish7537 3 ปีที่แล้ว +1

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

  • @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

  • @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

  • @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!

  • @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!

  • @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 ❤

    • @MikeShah
      @MikeShah  8 หลายเดือนก่อน

      Cheers!

  • @wika96
    @wika96 ปีที่แล้ว +1

    Great video Mike. Thank you very much.

  • @DCKUR
    @DCKUR 2 ปีที่แล้ว +2

    Very detailed, thanks for creating this video :)

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Thank you for the kind words!

  • @oribuun
    @oribuun ปีที่แล้ว +1

    Thank you so much for this amazing tutorial!

    • @MikeShah
      @MikeShah  ปีที่แล้ว +1

      Cheers, you are most welcome!

  • @lln6123
    @lln6123 21 วันที่ผ่านมา +1

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

    • @MikeShah
      @MikeShah  21 วันที่ผ่านมา

      Cheers!

  • @user-sz9ul1yp7l
    @user-sz9ul1yp7l 3 หลายเดือนก่อน +1

    Thank you for making difficult things seem easy 😍

    • @MikeShah
      @MikeShah  3 หลายเดือนก่อน

      Cheers!

  • @trido3815
    @trido3815 6 หลายเดือนก่อน +1

    Very good instructions. Thx.

    • @MikeShah
      @MikeShah  6 หลายเดือนก่อน

      Thank you for the kind words!

  • @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!

  • @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!

  • @samarthtandale9121
    @samarthtandale9121 3 หลายเดือนก่อน +1

    Thank you for the valuable lecture Sir!

    • @MikeShah
      @MikeShah  3 หลายเดือนก่อน +1

      Cheers, you are most welcome!

  • @startengine8838
    @startengine8838 ปีที่แล้ว +1

    Awesome video. Very well explained

    • @MikeShah
      @MikeShah  ปีที่แล้ว

      Cheers, thank you for the kind words!

  • @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 🙂

  • @ieduardoms
    @ieduardoms ปีที่แล้ว

    Thank you very much. It was really valuable.

  • @nicholasziglio
    @nicholasziglio หลายเดือนก่อน +1

    Thanks, this was really informative and useful!

    • @MikeShah
      @MikeShah  หลายเดือนก่อน

      Cheers!

  • @peyman_shabani
    @peyman_shabani 7 หลายเดือนก่อน +1

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

    • @MikeShah
      @MikeShah  7 หลายเดือนก่อน

      Excellent!

  • @stuartedward2965
    @stuartedward2965 ปีที่แล้ว +1

    very helpful! thank you

  • @kacperkrol4394
    @kacperkrol4394 8 หลายเดือนก่อน +1

    Great work!

    • @MikeShah
      @MikeShah  8 หลายเดือนก่อน

      Thank you! Cheers!

  • @kleinv7212
    @kleinv7212 10 วันที่ผ่านมา +1

    Bless you bro, thanks a bunch. It's very understandable👍🏻

    • @MikeShah
      @MikeShah  10 วันที่ผ่านมา

      Cheers!

  • @Kirmo13
    @Kirmo13 9 หลายเดือนก่อน +1

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

  • @KeplerEmeritus
    @KeplerEmeritus 2 ปีที่แล้ว +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  2 ปีที่แล้ว

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

  • @saivivekvalluru1369
    @saivivekvalluru1369 9 หลายเดือนก่อน +1

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

    • @MikeShah
      @MikeShah  9 หลายเดือนก่อน

      Cheers!

  • @yumiyonashi8518
    @yumiyonashi8518 16 วันที่ผ่านมา +1

    thank you sir..Helps a lot..

    • @MikeShah
      @MikeShah  16 วันที่ผ่านมา

      Cheers!

  • @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 :)

  • @pabloqp7929
    @pabloqp7929 ปีที่แล้ว +1

    omg how good is this 🔥💫🌿

  • @jfr644
    @jfr644 2 หลายเดือนก่อน

    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

  • @webcamdiary
    @webcamdiary ปีที่แล้ว +1

    Thanks a bunch!

  • @310gowthamsagar5
    @310gowthamsagar5 3 หลายเดือนก่อน +1

    this is great !

    • @MikeShah
      @MikeShah  3 หลายเดือนก่อน

      Cheers!

  • @NaveenKumar-cd8qh
    @NaveenKumar-cd8qh 2 ปีที่แล้ว +1

    Nice explanation, keep doing best 🙂

    • @MikeShah
      @MikeShah  2 ปีที่แล้ว

      Thank you for the kind words!

  • @Ab_Irato
    @Ab_Irato 2 หลายเดือนก่อน +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  2 หลายเดือนก่อน

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

  • @englishlnowledge486
    @englishlnowledge486 5 หลายเดือนก่อน +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  5 หลายเดือนก่อน

      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

  • @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 🙂

  • @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

  • @yashdeshmukh2662
    @yashdeshmukh2662 ปีที่แล้ว +1

    thanks

    • @MikeShah
      @MikeShah  ปีที่แล้ว +1

      Cheers, you are most welcome!

  • @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 TH-cam deleted perfectly fine comments 🤷

  • @peyman_shabani
    @peyman_shabani 7 หลายเดือนก่อน

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

    • @MikeShah
      @MikeShah  7 หลายเดือนก่อน

      Starting to plan something for Make. 👍

  • @muhammetkocak6903
    @muhammetkocak6903 4 หลายเดือนก่อน +1

    I hope you make video series about makefile and cmake

    • @MikeShah
      @MikeShah  4 หลายเดือนก่อน

      Cheers, I am thinking more about this :)

    • @muhammetkocak6903
      @muhammetkocak6903 4 หลายเดือนก่อน +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  4 หลายเดือนก่อน

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

  • @user-ul2mr7cy3f
    @user-ul2mr7cy3f 6 หลายเดือนก่อน +1

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

    • @MikeShah
      @MikeShah  6 หลายเดือนก่อน

      Cheers!

  • @Warmess
    @Warmess 5 หลายเดือนก่อน +2

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

    • @MikeShah
      @MikeShah  5 หลายเดือนก่อน

      Excellent!

  • @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

  • @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...

  • @jeffsad8391
    @jeffsad8391 18 ชั่วโมงที่ผ่านมา +1

    I have question:As begginner what should you learn first math or computer arhitecture ?

    • @MikeShah
      @MikeShah  9 ชั่วโมงที่ผ่านมา

      Probably best to learn a little of both as you go along -- however, if you start learning computer architecture, when there's some math you don't understand, you take the time to learn that math before proceding. So you don't necessarily have to learn one in a silo :)

    • @jeffsad8391
      @jeffsad8391 7 ชั่วโมงที่ผ่านมา +1

      @@MikeShah but what is order în learning?
      Math,computer arhitecture and organization,bios,operating system=what is the order to learn ?
      Beceause I need help

    • @MikeShah
      @MikeShah  7 ชั่วโมงที่ผ่านมา

      @@jeffsad8391 Start with a simple project (e.g. a game) and learn as you go.

    • @jeffsad8391
      @jeffsad8391 7 ชั่วโมงที่ผ่านมา +1

      @@MikeShah like a little project?

    • @MikeShah
      @MikeShah  7 ชั่วโมงที่ผ่านมา

      @@jeffsad8391 exactly! Believe it or not, even the simplest of projects will reveal what to learn 🙂

  • @coolwinder
    @coolwinder หลายเดือนก่อน +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  หลายเดือนก่อน +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 หลายเดือนก่อน +1

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

    • @MikeShah
      @MikeShah  หลายเดือนก่อน +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 หลายเดือนก่อน +1

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

    • @MikeShah
      @MikeShah  หลายเดือนก่อน +1

      Cheers ​@@coolwinder

  • @edhermisaelcarbajalrosales1613
    @edhermisaelcarbajalrosales1613 9 หลายเดือนก่อน

    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.

  • @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