CMake Tutorial EP 2 | Libraries and Subdirectories

Поділитися
Вставка
  • Опубліковано 17 гру 2024

КОМЕНТАРІ • 135

  • @YourCRTube
    @YourCRTube 4 роки тому +53

    This is actually a really nice and practical tutorial (especially for someone that already knows the overall C++ build process and is a beginner only in cmake alone).

  • @thepatcher3946
    @thepatcher3946 4 роки тому +84

    a good video but when u started fixing your mistake in the header and adding (for me random) stuff to the top level CMakeLists File i got really confused. and i am not sure i understood all the different target_links and target_includes

    • @kevinpatterson5558
      @kevinpatterson5558 3 роки тому +5

      Those extra commands are exactly what I needed to know how to do. So its a good intro example imo.

  • @vitorroriz
    @vitorroriz 3 роки тому +15

    I love the fact that you didn't edit the video and are showing the trial and error approach that is common for all of us when learning/remembering of something. Nice work!

  • @mohammadramezani2282
    @mohammadramezani2282 2 місяці тому

    most tutorials dont show the error solving process which beginners like myself struggle a lot with it but now i know what mistakes i might make when doing this stuff. thnx for this tutorial

  • @mh6790
    @mh6790 3 роки тому +12

    Very good tutorial! The errors/fixes are so helpful because it mimics development.

  • @eslamt1993
    @eslamt1993 2 роки тому +21

    Correction Here, After doing some tests. the line target_link_directories does nothing here . It will still be able to link without it. That's because cmake is aware of the target adder from the sub-directory and will be able to link with it normally.

    • @AndreiSokolov-k7j
      @AndreiSokolov-k7j 8 місяців тому

      yeaaah, thank you, I also was confused do add_subdirectory also provides knowledge about inner directories and that's true. for header files you need to specify include directories and maybe some others idk

    • @VuaTommy
      @VuaTommy 6 місяців тому

      True, I tested with that too

  • @giacomosanguin392
    @giacomosanguin392 4 роки тому +5

    just studied cmake at university, and i didn't understand much (actually almost nothing). Now i've discovered your tutorials and i've finally started understanding a bit! i hope to be well prepared at the end of your playlist of videos

    • @XNaruto25
      @XNaruto25 4 роки тому +1

      What undergrad teaches this?

  • @snippletrap
    @snippletrap 2 роки тому +2

    It worked for me with just add_subdirectory and target_link_libraries. The other commands weren't necessary. But then I didn't derp in the adder code! Thanks for this series, very helpful.

  • @pavelovchinnikov4227
    @pavelovchinnikov4227 3 роки тому +7

    You are really OURLORDANDSAVIOR! Thank you so much for this videos!!!

  • @seatoaster1491
    @seatoaster1491 3 роки тому +1

    Best cmake education I’ve had yet

  • @SauvikRoy
    @SauvikRoy 2 роки тому +1

    Very nice tutorial covering lots of information in a beginner friendly way. Thanks!

  • @deepikagoyal07
    @deepikagoyal07 Рік тому

    It was very useful. Just what i needed at the moment. Thanks so much.

  • @LFWarsen
    @LFWarsen 4 роки тому +4

    You absolute legend! Thanks so much for this tutorial, man.

  • @MikCish
    @MikCish 3 роки тому

    best cmake series on the tubes

  • @vladyslavtkach2209
    @vladyslavtkach2209 4 роки тому +10

    Got two points to my overall score. Now I have two

  • @1234minecraft5678
    @1234minecraft5678 2 роки тому

    I love you for this series, help a lot

  • @sammyiboi
    @sammyiboi 4 роки тому +2

    love the desktop sound effects

  • @Krasnoff64
    @Krasnoff64 3 роки тому +1

    Thank for good feature covering. You really safe a lot of time

  • @carlosdalomba
    @carlosdalomba 4 роки тому +14

    Great tutorial again! :D
    Also I found that..
    1.
    target_include_directories(...) is required to do the simple #include "whatever.h" without needing to include the folder path in your C++ files
    2.
    target_link_libraries(...) is required to link the main.cpp's output to the library's output so they can call each other in the build
    (I still need to understand what linking is more specifically)
    3.
    target_link_directories(...) was NOT required, and my build (CMake, Make, and running the executable) still fully worked without this. (Haven't looked into the docs on this function, since I'm a beginner at CMake for now haha).

    • @YourCRTube
      @YourCRTube 4 роки тому +3

      target_link_directories is indeed not needed here because the library is a subproject that cmake is building

    • @vladyslavtkach2209
      @vladyslavtkach2209 4 роки тому

      Did you find out the difference between 2 and 3 so far?

    • @VuaTommy
      @VuaTommy 6 місяців тому

      @@vladyslavtkach2209 I think you don't need this answer but maybe someone does :D
      use target_link_directories(...) when you already have a static/dynamic library (*.so or *.a) to let cmake find that in the folder (and then cmake will follow target_link_libraries(...) command to add that library to project)
      In the video above, we don't need target_link_directories(...) because :
      - We do not have *.so or *.a already
      - That lead to the command add_library that will compile the library into .so/.a with the "name tag" : adder
      From this it already inside the project so we do not need to find the dir of lib anymore

  • @RobinDuckett
    @RobinDuckett 3 роки тому

    I was laughing the entire time, saw you call the function in the header "adder" 🤣

  • @tonywtyt
    @tonywtyt 2 роки тому +2

    I like using various editors, but I hate fighting with IDEs and trying to configure them to build my stuff. I'm actually a old C programmer that's familiar with Make, but I've been professionally been working with Java and its build systems. I've now personally move away from my Win10 machine and working with a Linux distro and playing with same C/C++ game development stuff. I heard about CMake and thought it was only a variation of Make, so it made no sense to me when I first looked at it years ago and scared the crap out of me! Thanks for grabbing my attention and show us how cool this tool is! And , BTW, I made the same damn mistake with my missing new include in main.cpp : )

  • @peterhayman
    @peterhayman 3 роки тому

    CMake Episode 2: Attack of the typos :) thanks for the vid bro, makes all this feel less scary

  • @kaustubhcs07
    @kaustubhcs07 3 роки тому +1

    Keep making more videos! Love your videos!

  • @denizural5390
    @denizural5390 3 роки тому +1

    Great CMake playlist. I find it useful to open the verbosity via VERBOSE=1 when CMake complains. Then it is easier to debug.

  • @eastonsuo
    @eastonsuo 2 роки тому +1

    actually all you need is
    add_subdirectory(Adder)
    # target_link_libraries( ... ... ...)
    target_link_libraries(${PROJECT_NAME} adder)

  • @dominiksuszczewicz7519
    @dominiksuszczewicz7519 4 роки тому +2

    Good stuff, I really enjoy the tutorials!

  • @Martin-yo8wh
    @Martin-yo8wh 2 роки тому +1

    Kinda got confused of the behavior between target_link_directories and target_include_directories. So target_link_directories creates the directory where the built library will be located; on the other hand target_include_directories DOES NOT create a directory, but it references an already existing directory so it can know that such exists (thereby making including files directly in it possible) ? tl;dr of confusion: target_link creates directory, target_include does not?

  • @aaaa1339
    @aaaa1339 3 роки тому +1

    I appreciate your approach. No clickbait nonsense, no annoying faked energy level, no channel-level meta commentary, e.g. "sorry i haven't been uploading recently". Straight to the point and earnest. Also I appreciate that you took the time to make those text-insertions whenever you felt like you weren't clear enough in your words. Having said that, I think this video could have benefited from a re-recording.

  • @clintonreisig
    @clintonreisig 2 роки тому +1

    Question: If I obtain a C library or code a C library myself, may I include it in a CPP project (such as in this tutorial) as a library in the directory and will the C library be compiled separately and linked with main.cpp at the end? If yes, is this how other language libraries (such as written in C# or Python for example) can be compiled separately (under CMake) in the application directory and linked at the end with the main.cpp into an executable?

  • @azazulhaque9375
    @azazulhaque9375 2 роки тому

    how can we link a static library to a main static library on which it has dependency using target_link_libraries ?

  • @kangzheng2067
    @kangzheng2067 Рік тому

    hi, Tim what are the “public “ and “private “ used for?

  • @raahimfareed
    @raahimfareed 3 роки тому

    I have a single include folder with all the header files in it and all my cpp files in a src folder, how can I add that in my CMakeLists?

  • @X.A.N.A..
    @X.A.N.A.. 2 роки тому

    How do you have sound effects in vscode?? It's cool

  • @Caltuit
    @Caltuit 3 роки тому

    Thanks for these introduction videos!

  • @akashgillella
    @akashgillella 2 роки тому

    Loved the tutorial

  • @pureplay7
    @pureplay7 2 роки тому

    Thanks for the tutorials :D

  • @Pyrografpl
    @Pyrografpl 2 роки тому

    I have bought and started reading book about cmake and understand nothing… official tutorial is a mess - go to step 7 then come back to step 3 and then… aww. Your video is gr8! Thx 🎉

  • @Gloryisfood
    @Gloryisfood 3 роки тому

    Is target_link_directories() not necessary that without the line the build should still pass?

    • @CodeTechandTutorials
      @CodeTechandTutorials  3 роки тому

      I think there are ways around it, but if it can't seem to find the library you are linking to, give your target the directory path to search should resolve it.

  • @BOURNE399
    @BOURNE399 3 роки тому

    love the desktop adorable sound effects!!!!!! How to change that?? Would you mind also give a tutorial on that, sir?

    • @CodeTechandTutorials
      @CodeTechandTutorials  3 роки тому +1

      Thanks. The sounds come with MX Linux, the OS I was using here. I believe it was in the sound options.

  • @anon343
    @anon343 2 роки тому

    Does it matter what order you enter .cpp files into the "add_executable"?

  • @prajwaldeepkhokhar7416
    @prajwaldeepkhokhar7416 3 роки тому

    i have a question, we never mentioned we are using gcc or g++, yet it compiles the cpp files with g++ apparently, how does cmake know that? And if it can detect based on source code, is there any limitation (like lets say it cannot detect java code or so?)

    • @CodeTechandTutorials
      @CodeTechandTutorials  3 роки тому

      It is made to detect it. I'm not sure of all the limitations, but the do have extensive documentation.

  • @catalinvoineag6344
    @catalinvoineag6344 3 роки тому +1

    Very helpful, can you please put a link to the repository?

  • @tamasboros1798
    @tamasboros1798 4 роки тому +2

    Do you always need to use "target_link_directories"? Or is it recommended? My example works without it.

    • @CodeTechandTutorials
      @CodeTechandTutorials  4 роки тому +5

      Generally only if it doesn't know where to find the link library.

    • @tamasboros1798
      @tamasboros1798 4 роки тому

      @@CodeTechandTutorials Thank you!

    • @YourCRTube
      @YourCRTube 4 роки тому

      @Brown Smith In this case it is not needed, because the lib is a subproject (a "target") and cmake knows all about it, literally.

    • @michaelmueller9635
      @michaelmueller9635 3 роки тому +1

      In the official Doc it says:
      Dont use it, if u can do it another way -> cmake.org/cmake/help/git-stage/command/target_link_directories.html
      I guess, u dont need it here.

    • @michaelmueller9635
      @michaelmueller9635 3 роки тому +1

      PS.: Or u need it, when u did the derping before xD

  • @user-cc8kb
    @user-cc8kb 2 роки тому

    Great tutorial! Thanks a lot :)

  • @saadsaad17
    @saadsaad17 2 роки тому

    Is there a way to include the header file "adder.h" without going down a directory explicitly like that, "Adder/adder.h"? Through the CMakeLists.txt for example?

    • @saadsaad17
      @saadsaad17 2 роки тому

      Nvm I was too hasty lmao

  • @amrtcpp6203
    @amrtcpp6203 3 роки тому

    Can someone explain for me @15:33 , thanks

  • @calenjackman1
    @calenjackman1 3 роки тому

    How would you use cmake to include a directory full of libraries you want access to in main?

    • @calenjackman1
      @calenjackman1 3 роки тому

      for instance a folder containing two other libraries (adder and subtractor?)

  • @PerfectHilton
    @PerfectHilton 3 роки тому

    Exactly what i needed at the moment! Thanks

  • @naoryehuda6830
    @naoryehuda6830 3 роки тому

    after running Cmake, why do you run make again,
    doesn't Cmake do it behind curtain?

  • @alex85907
    @alex85907 3 роки тому +2

    Great Vid, learned a lot, thanks :)

  • @Bananananamann
    @Bananananamann 4 роки тому +1

    What do I get for my 2 Bonus points?

  • @duckhe6143
    @duckhe6143 Рік тому

    This is a very easy-understood tutorial. By the way, you definitely look like Zeus.

  • @nischalsehrawat2130
    @nischalsehrawat2130 2 роки тому +1

    I think target_include_directories should be in the library not in the main CMakeLists.txt file

  • @itsgalaxy2407
    @itsgalaxy2407 4 роки тому +5

    nice! how about linking an external library next

    • @CodeTechandTutorials
      @CodeTechandTutorials  4 роки тому +2

      Yep that is next episode after this.

    • @h.hristov
      @h.hristov 4 роки тому

      @@CodeTechandTutorials haha, i was about to ask the same thing. im following your series so far, it's really good for a beginner, thank you

    • @milanky
      @milanky 4 роки тому +1

      Checkout the Beginner/Intro CMake Course at www.udemy.com/course/master_cmake/?referralCode=D08DF343ABAE2835C3B7

  • @chuongnguyen4980
    @chuongnguyen4980 3 роки тому

    Thanks for your tutorial. Very helpful.

  • @guoliangwang4826
    @guoliangwang4826 3 роки тому

    Great tutorials , but why your screen blurred?

  • @hanniballecter1734
    @hanniballecter1734 3 роки тому

    How do you organize and build code that has both C and C++ in it?

    • @julienguay7524
      @julienguay7524 3 роки тому +1

      It doesn't really matter, as long you don't try to use any cpp function in a c file, otherwise you have to make it compatible with
      extern "C" {
      your code in that cpp file wich must be compatible with another c file
      }

    • @hanniballecter1734
      @hanniballecter1734 3 роки тому

      @@julienguay7524 Yeah. I have written it using the extern keyword. I was initially hoping to have separate C files, link them together and then use them as static library for the C++ code.

  • @justcplusplus2552
    @justcplusplus2552 2 роки тому

    What is the benefit of using "libraries" internally. I though that a library is code which should be reused in multiple projects. So, if you just declare code of a subdirectory as library you would have to copy the code to another project and add it as subdirectory too. Where is the point of add_library() and then adding this "library" directly into your main project instead of making a project for the library outside of the root directory of this project and add it somehow later on, so that I could be used by a second project as well.

    • @CodeTechandTutorials
      @CodeTechandTutorials  2 роки тому

      Generally reusability and ease of exporting them, and another big thing is for testing correctness, as they could each have their own test main file.

  • @BigTarkus
    @BigTarkus 3 роки тому

    Love the vids, very helpful stuff!

  • @danielnoriega6655
    @danielnoriega6655 2 роки тому

    It would've been nice to see that example organized in a standard C project with src, lib, inc, and out folders, making use of dynamic standard libc and static local libs =P

  • @ErikBlueGuitar
    @ErikBlueGuitar 3 роки тому

    Hi Tim, I am doing a Python simulation where I am calling a C file with functions (via ctype bindings), which in turn calls another C library. Since I use Python to decide when to call what function, I do not have a main.cpp. Would this still compile? Or should I make an empty main() in cpp? Thank you for your videos!

    • @jefflongo
      @jefflongo 2 роки тому

      You can just compile it as a static library and you do not need a main

  • @reinioyeah5467
    @reinioyeah5467 3 роки тому

    Great tutorial 👍

  • @twopie79
    @twopie79 3 роки тому

    Do you need both target_link_directories and target_link_libraries? Also great content, thank you!

    • @Mohammed24441
      @Mohammed24441 2 роки тому

      target_link_directories is not needed

  • @leonardodavinci4259
    @leonardodavinci4259 2 роки тому

    Thanks! My Lord & Savior

  • @markharrington5826
    @markharrington5826 3 роки тому

    These are very good tutorials Have made links to this and all others regarding CMake to Faceboook

  • @beepst
    @beepst Рік тому

    Aphex Twin teaches very good. :)

  • @masoodkamandy5370
    @masoodkamandy5370 3 роки тому +2

    Really love this series. My question is: In the CMakeLists.txt for the library, why don't we need to include a reference to the header file also?

    • @tissuepaper9962
      @tissuepaper9962 3 роки тому +4

      The header file is only necessary to build main.cpp, all it does is tell the compiler how to pass arguments to these functions. It will compile main with references to these functions under the assumption that you're going to link another object file with the full definitions when you put together the executable. There's an understanding between you and the compiler that those functions will be fully defined later, the header is just a stand-in.
      When you're compiling the library code, the compiler doesn't need to have a stand-in for those function definitions because they're right there in the file you're compiling. I don't think it would actually hurt anything to include the header, it's just not strictly necessary.

    • @learningcode314
      @learningcode314 2 роки тому +1

      We don’t need to specify an include location in the CMaleLists.txt for Adder because adder.cpp is including a header that is located in it’s same directory. If adder.h was located in a separate directory then we would need to either specify the whole relative path to it (similar to when he did Adder/adder.h in main) or add that include directory to our system headers through Adder’s CMakeLists.txt. I think using “” makes it so the file’s directory is first searched followed by system headers, while the skips the local search and just looks into system headers.

  • @squarerootof2
    @squarerootof2 4 роки тому +1

    I did CMake the first one, but normally I just use qmake & QT.

    • @CodeTechandTutorials
      @CodeTechandTutorials  4 роки тому

      That'll work. There are so many different ways cmake becomes integrated into tools. Trying to give the base explanation first and I plan on talking about some of those tools later. QMake probably inovkes CMake. I've used qmake and qt in the past but it has been a few years.

  • @0xB16B00B
    @0xB16B00B 3 роки тому

    Thank you very much...

  • @amrtcpp6203
    @amrtcpp6203 3 роки тому

    Please increase the microphone volume

  • @sadashivsahoo
    @sadashivsahoo 3 роки тому

    How to get and link libatlas.so.3.1.2

  • @hosseinbeiranvand7169
    @hosseinbeiranvand7169 3 роки тому

    very helpful! thanks!

  • @sarthaksharma4816
    @sarthaksharma4816 3 роки тому

    Thank you

  • @danielkurt7545
    @danielkurt7545 2 роки тому

    thank you best

  • @ELECTRONICWALKS24
    @ELECTRONICWALKS24 3 роки тому

    thankyou!!!!!!!!!!!!

  • @hassannawazish9300
    @hassannawazish9300 3 роки тому

    Thanks Man...........!

  • @paulozhang9346
    @paulozhang9346 3 роки тому

    Great tutorial!
    I’m a .net architect, recently thinking of creating a c++ system.
    Then I look at you video and see you struggling with typing the correct names linking library.
    This is way more easier with C#, we can create a few projects, make reference among them,and write a few hundred lines of code. Then compile and run successfully in the first attempt. What’s more, we can deploy it to Linux now with .net core.
    Unless we really need the c++ performance, I just don’t see the necessity of building a complex system with C++. It’d devastating to manage a system with dozens of libraries.
    What’s your opinion?

    • @k-tech2937
      @k-tech2937 3 роки тому +1

      do it often enough and this all gets trivial. It is a bit more cumbersome than .net Projects, but it's not as bad as it seems ;)

  • @handlehandle12322
    @handlehandle12322 3 роки тому

    Bad choice of background for a video imo, on a phone it's hard to see the letters in comparison to white background and black text

  • @domagojbosnjak75
    @domagojbosnjak75 3 роки тому

    2 points in the pocket

  • @Popart-xh2fd
    @Popart-xh2fd 9 місяців тому

    make not found!

  • @luojia4923
    @luojia4923 Рік тому

    I felt confused, sad ~

  • @recessiv3
    @recessiv3 3 роки тому +1

    Great tutorial, but watching you debug errors makes the video tedious. If it's a common and confusing error that makes sense, but syntax errors really don't need to be in the video

  • @bu3778
    @bu3778 2 роки тому

    If Heisenberg did comp sci instead of chemistry

  • @larsgustafsson215
    @larsgustafsson215 2 роки тому

    Thanks for a good tutorial, but Zeus is spelled Zeus.

  • @anshumanmajumdar7361
    @anshumanmajumdar7361 4 роки тому +2

    Awesome tutorial series but the misspelled ZEUS is triggering my ocd lmao smh...

  • @natura-g5i
    @natura-g5i 4 роки тому

    nice

  • @swengeer
    @swengeer Рік тому

    Informative video, but would be faster if you did all the typing, then simply discussed the results. Coding along is rather slow.

  • @corradosteri9150
    @corradosteri9150 3 роки тому +1

    This video should be brought as an example on how not to make a tutorial. Confusing to say the least.

  • @Fareoneo
    @Fareoneo 2 роки тому

    imagine doing a tutorial on something that you don't know how it works

  • @TopConductor
    @TopConductor 2 роки тому

    the tutorial could have been good, but to be honest, it lacks a little bit of consistency. I found it hard to follow and understand after you started adding many new functions without explaining what they do.

  • @mydoghasschizophrenia
    @mydoghasschizophrenia 3 роки тому

    Man you should prepare files and code for your tutorial, because I for one don't really care about how you write that code in .cpp files, and I'm not really excited by you fixing your own errors.

  • @viktoriyamankovskaya5906
    @viktoriyamankovskaya5906 3 роки тому

    i have a question: do u have a girlfriend?)

  • @bobweiram6321
    @bobweiram6321 Рік тому

    What a useless tool! A build script to build another build script? You declare an executable and then link its libraries? How can it technically be an executable without the required libraries? God save us from the UNIX mediocrity!

    • @CodeTechandTutorials
      @CodeTechandTutorials  Рік тому

      It's cool that you have found some better tools and methods. Care to share?

  • @ShridharBenni-bx2tq
    @ShridharBenni-bx2tq Рік тому

    my project is working fine without adding this line target_link_directories(${PROJECT_NAME} PRIVATE Adder/), can someone explain me why it is happening tike this?

    • @CodeTechandTutorials
      @CodeTechandTutorials  Рік тому

      My guess would be: either you are not using anything from the library, or are using a version of the executable that was previously built successfully.