How To Create A Library And Split A Program Across Multiple Files | C Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2022
  • How to create a library and split a program across multiple files in C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

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

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

    A best practice when creating header files is to add include guards to prevent a problem called double inclusion, check out this video to learn more! th-cam.com/video/pF1_fXz5zN0/w-d-xo.html

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

    in 6 months of university i didnt understand this...
    now i learned it in just 6 minutes from this video - thanks, you just made my coding a hell lot smoother and cleaner!

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

      I'm so glad to hear that, and you're welcome Marie! :-D

  • @khalilebdelli6199
    @khalilebdelli6199 ปีที่แล้ว +24

    i swearrrrrr, after a whole year of computer science and research , nothing beats this tutorial , thank you sooooooooo much

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

      You're very welcome, I'm really glad to hear that you enjoyed it! :-)

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

      I like your comment before watching it, hope all people appreciate the precious works like this.

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

    This must be the best tutorial about this subject I've ever seen. Thank you so much! I was trying to create a library for a 100-line code function without success, but I saw your video and finally manage to do it!

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

      You're very welcome, I'm glad the video was helpful for you! :-)

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

    the only C tutorial that makes sense. Using a terminal and manual compilate instead of an IDE. Thank you for making this±

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

      You’re welcome, I’m glad you enjoyed it! :-)

  • @JohirulIslam-lm2vz
    @JohirulIslam-lm2vz ปีที่แล้ว +2

    This is a great channel to learn C. I love it very much. Thanks!

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

      You're welcome Johirul, that's awesome to hear that you enjoy the channel! :-)

  • @MF18-2020
    @MF18-2020 ปีที่แล้ว +2

    man thank you so much because you tutorials are so understandable to me

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

      You're very welcome, I'm glad you enjoy them! :-)

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

    Perfectly put together, thanks chief

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

    Very informative in such a short time ty

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

    Thank you very much for this worderful opportunity provided, can't wait for the video on the use of Make file

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

      Awesome! I'm looking forward to making that one as well, though it will be a bit more extensive/longer. :-)

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

    6 useful minutes.
    Hats to you off sir.

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

      Thank you Mohamed! I’m glad you enjoyed it! :-D

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

    Thank you very much for your tutorial.

  • @Mjerjawi
    @Mjerjawi 10 หลายเดือนก่อน +3

    Thank you so much for your dedication, sir. Whenever I have a C-related question, this channel is my ultimate go-to. The effort you've put into creating such a valuable C resource is truly commendable.
    If possible, could you make a tutorial on cmake?
    Your expertise would greatly benefit the community.

    • @PortfolioCourses
      @PortfolioCourses  10 หลายเดือนก่อน +2

      You're welcome, I'm really glad to hear this channel has been valuable for you. :-) I've always wanted to make a video on makefiles, but I just haven't found the time yet. I still want to do it one day though, so hopefully I'll be able to.

    • @Anonymous-XY
      @Anonymous-XY 6 หลายเดือนก่อน

      @@PortfolioCourses Thank you.

  • @comic-typ5919
    @comic-typ5919 2 ปีที่แล้ว

    I just include every library i need in the header file and include the header file in the c files, works so far pretty good

  • @rannvijaysingh1
    @rannvijaysingh1 27 วันที่ผ่านมา +1

    Thanks your videos are amazing.
    Can you make some videos how we add GUI to our C files.

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

    Great video, right on point!

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

    Hello sir, I have query like how library.h file will interface with library.c file? Since we have created library.c file but not added to main file or even library.h. how does this interface work? Please explain one.

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

    Sir this is great...keep up the excellent work....

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

    You saved my life Thanks a lot

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

    Thanks for this short and very useful video. Did you ever get tot make that video about 'make'?

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

      You're welcome! :-) And not yet, but it's still on my todo list for sure. :-)

  • @Victor-fg1wv
    @Victor-fg1wv 2 หลายเดือนก่อน

    i tried your example on ipad on a-shell app and when i try to compile i cant, it sais segmentation fault. i dont know what is hapening please helpp

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

    Thanks for the video.

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

    i want to keep the library.c file in seprate folder will this work then

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

    thankyou very much sir!

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

    Thank you sir

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

    is this a concept of ADT/ADT itself?

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

    if we want a library in screen.hpp and screen.cpp alongwith main.cpp, would we include it in all three? if not, to which files should we add it?

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

      About the same as the stdio.h in the example. You include the headerfile in those c(pp) modules that *use* a function from that library. In your main you do not need to include any h(pp) files of what is not used in main.

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

    Wait, do I not need to include the header file in the c file? (Ie include library.h in library.c?). Should you?

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

      Good question Arthur! :-) It is not required, unless the .h file includes things like preprocessor directives like #define, in which case we wouldn't want to have to redefine them in the .c file. In terms of "should we", it won't make a difference to the how the program executes, but it could be beneficial to include the .h file in the sense that the compiler would "double check" that the function declarations in the .h file match the definitions in the .c and flag this for us if they do not.

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

    @5:50 did u ever make that other video on makefiles by any chance? I couldn't find it on your page.

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

      Not yet, but that's one of the most requested topics I've ever had. I really want to do it, the problem is even though I know about makefiles, I'll need a day where I can research to make sure I get my facts straight before I cover it. As a result I likely won't be able to cover it until December-January timeframe. But I do really want to cover it! :-)

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

      @@PortfolioCourses gotcha. yeah there aren't as many good videos on makefiles as there are on other stuff, so I can see why the demand would be there.

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

    thank you so much

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

    Hi!
    Can you have a tutorial on how to run C in Vs Code?

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

      I think we can do that someday yes, thanks for the idea. For now we have these videos on setting up environments, the first one shows how to setup an environment like the one used in this video on a Mac:
      th-cam.com/video/RCsfDcvREzU/w-d-xo.html
      th-cam.com/video/gq_ZXCuRhU4/w-d-xo.html

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

    is there any video which talkes about how to use gcc? ı couldnt understand main point gcc.

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

      I don’t have a video on using gcc specifically, that’s a video I’m hoping to make one day. :-)

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

      @@PortfolioCourses Thank you Kevin. I hope ı am going to meet you one day. Have a good day.

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

      You're welcome! :-) Maybe one day our paths will cross, I hope you have a good day too!

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

    So I have a question what if I want to use the add function created in this library in another c file what is the process of that lets say I created a library with an add function and it gave me a lib1.a file how do I use this file into another c program to use the add function in lib1.a file I cannot find this anywhere or maybe I am just too dumb to understand and if you have already made a video on that can you please link it Thank you.

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

      It's a good question Awab. 🙂 Basically to include it in "another program" it would be exactly like what we did here, we could re-use the exact same library exactly as it is written in another program by copying the files. We could compile it in the same way too. Now as a practical matter this can become difficulty and confusing because if two programs want to use the same library, it's going to make compilation a bit more difficult. We could copy the library files and place them in each directory, but then if we make changes to the library files we would need to change them in both places. We could keep the library files in one folder, and then use the gcc compiler and reference the file path of the library but that's going to be a longer command now. To clear up this sort of difficulty, people tend to use "makefiles", a tool for making compilation of more complex programs easier. One day I really want to make a video on makefiles but I have not had time just yet. 🙂

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

      @@PortfolioCourses Thanks man. I really appreciate that and I hope you find the time to make the video because it will be very helpful and your teaching style is very good.

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

      You’re welcome Awab! :-)

  • @gengi-po3cx
    @gengi-po3cx 5 หลายเดือนก่อน

    thanks

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

    When you are going to drop Makefile video?

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

      I have wanted to do that video for a long time, I still want do it but I’ve found linger videos harder to make. I’m going to try something different this next year to see if it helps. :-)

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

    Hello,
    Hope you are doing good.
    I'm going start my career as C/CPP developer, Can you tell will there be jobs for C/CPP developer in future,since many people are saying these languages are becoming obsolete.
    Thank you.

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

      I'm doing good, I hope you're doing good too! :-) People have been saying for a long time that C/C++ will go away. But C++ is used widely in the video game industry, C gets used in embedded systems, etc. Most programmers learn many different things and languages over the course of a career, and things learned in C/C++ will carry over to other languages as well. So personally, I would suggest focusing on the type of software you want to build and learn whichever languages are most often used to make that type of software.

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

    I've worked with Code Blocks so far, but when I tried VS Code I had many issues compiling my multi-file projects.
    I researched many, many days but as I just started learning how to code, this things about .json archives, Makefiles or the gcc commands were just too difficult to understand for me.
    With this single video, I can at least say I finally understand why I gotta do all this things with VS Code in the first place. Thank you so much!
    I'd really aprecciate if you make a video explaining how to set these things up, if you haven't done it already. Your explanations are great!

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

      Glad to hear it helped Franco! 🙂 Setting up which things exactly do you mean? Makefiles? Or compiling multi-file projects in VS Code?

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

      @Portfolio Courses I believe makefiles are the most difficult thing, since you've explained how to compile multi-file projects and I understood it. I remember needing to include the .c files along with the headers in my main because otherwise it wouldn't "link" the files or compile them properly, which is what I don't understand yet.
      But then I found out there are also these .json files to indicate the preprocessor how to compile our programs, so I guess that plays a part too, right? At least that's what I understand, please correct me if I'm wrong.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +4

      @@FrancoNSosa JSON files might play a role with Visual Studio and/or Visual Studio Code in terms of configuration, but they're not really a true part of C compilation, technically speaking. And OK that's good feedback thank you, I've had a number of people tell me they would like a video on makefiles so I'm going to try to do that sometime sooner rather than later. And maybe I can explain more about Visual Studio Code too.

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

      @@PortfolioCourses Great thank you so much!! Will wait for it :)

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

    Hello sir , i would like to know if you can make a video about makefile please

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

      Makefiles is a topic I really badly want to cover, I might be able to make a basic introduction video soon but I also want to make a series of videos and beginners course eventually. :-)

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

      @@PortfolioCourses thank you Sir , looking forward to that :D have a good day

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

      You too! :-)

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

    I am trying to run this in vs code but I cant.

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

      Do you have the gcc compiler installed? Does it give any error message?

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

    Someone tell me, why he is not including library.h ???

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

      He does #include the library.h. Where else would you expect it included? Possibly you are wondering why it is not in the gcc-line. Or you are wondering why there is no #include "library.c". A "rule of thumb" is #include .h files and add .c files to your gcc command. The why this is so, and what can be in each of the files, is the deeper understanding of pre-processing, compilation and linking that goes on, which is alluded to in the video.

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

    thanks for Your efforts, Please!!! you can make a video about MAKEFILE It's helpful on this part (compiling many files at the same time)

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

      You're very welcome! That's something that's been requested a few times and it's definitely on my 'videos to make' list. :-)

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

      @@PortfolioCourses 👌👌🧡

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

      @@appdeveloppement532 ❤

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

    teach us how to read and copy binary information from .exe files

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

      I don’t have much experience reading exe files, but I may be able to put something together in the future. :-)

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

    OK. now put those header files in a different folder (headers ) and the main.c in a different folder (src) and make it work like that

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

      So at that point, we would want to use a makefile to handle that situation. This website covers makefiles: makefiletutorial.com/. I don't have a video covering makefiles, but it's something I would like to do one day if I can ever find the time. :-)

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

    Where is the makefile video 😢

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

      I still want to make it, the problem is time... that video takes a long time to make it good. :-(

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

    i love u