CMake Tutorial EP 2 | Libraries and Subdirectories

  Рет қаралды 117,179

Code, Tech, and Tutorials

Code, Tech, and Tutorials

4 жыл бұрын

this episode has been re-done, new version here: • CMake Tutorial EP 2 | ...
full CMake playlist: • CMake Tutorial EP 1 | ...
repo: github.com/codetechandtutoria...
Find me, support me:
Stream: / overridetheprogram
Patreon: / codetechtuts
One time donations: www.paypal.com/paypalme/matte...
Shop via my Amazon Affiliates Link: amzn.to/3bVQ9X0
Business inquiries: codetechtuts@gmail.com
Thanks for coming to the channel to check out a video on Code, Tech, and Tutorials.

Пікірлер: 135
@YourCRTube
@YourCRTube 3 жыл бұрын
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 3 жыл бұрын
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 жыл бұрын
Those extra commands are exactly what I needed to know how to do. So its a good intro example imo.
@vitorroriz
@vitorroriz 3 жыл бұрын
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!
@mh6790
@mh6790 2 жыл бұрын
Very good tutorial! The errors/fixes are so helpful because it mimics development.
@eslamt1993
@eslamt1993 2 жыл бұрын
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.
@englishanywhere2692
@englishanywhere2692 Жыл бұрын
Perhaps that is why VSCode colored the line white "target_link_directories(${PROJECT_NAME} PRIVATE Adder)" while all other lines were blue ....It was a mystery until I read your comment. Thanks 😀
@user-ib3ev5pl2t
@user-ib3ev5pl2t 3 ай бұрын
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 Ай бұрын
True, I tested with that too
@LFWarsen
@LFWarsen 3 жыл бұрын
You absolute legend! Thanks so much for this tutorial, man.
@pavelovchinnikov4227
@pavelovchinnikov4227 3 жыл бұрын
You are really OURLORDANDSAVIOR! Thank you so much for this videos!!!
@SauvikRoy
@SauvikRoy 2 жыл бұрын
Very nice tutorial covering lots of information in a beginner friendly way. Thanks!
@giacomosanguin392
@giacomosanguin392 3 жыл бұрын
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 3 жыл бұрын
What undergrad teaches this?
@Krasnoff64
@Krasnoff64 3 жыл бұрын
Thank for good feature covering. You really safe a lot of time
@snippletrap
@snippletrap Жыл бұрын
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.
@vladyslavtkach2209
@vladyslavtkach2209 3 жыл бұрын
Got two points to my overall score. Now I have two
@sammyiboi
@sammyiboi 3 жыл бұрын
love the desktop sound effects
@Caltuit
@Caltuit 3 жыл бұрын
Thanks for these introduction videos!
@1234minecraft5678
@1234minecraft5678 Жыл бұрын
I love you for this series, help a lot
@MikCish
@MikCish 3 жыл бұрын
best cmake series on the tubes
@kaustubhcs07
@kaustubhcs07 2 жыл бұрын
Keep making more videos! Love your videos!
@seatoaster1491
@seatoaster1491 2 жыл бұрын
Best cmake education I’ve had yet
@deepikagoyal07
@deepikagoyal07 7 ай бұрын
It was very useful. Just what i needed at the moment. Thanks so much.
@BigTarkus
@BigTarkus 3 жыл бұрын
Love the vids, very helpful stuff!
@peterhayman
@peterhayman 3 жыл бұрын
CMake Episode 2: Attack of the typos :) thanks for the vid bro, makes all this feel less scary
@dominiksuszczewicz7519
@dominiksuszczewicz7519 3 жыл бұрын
Good stuff, I really enjoy the tutorials!
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Awesome, thank you!
@chuongnguyen4980
@chuongnguyen4980 3 жыл бұрын
Thanks for your tutorial. Very helpful.
@pureplay7
@pureplay7 2 жыл бұрын
Thanks for the tutorials :D
@akashgillella
@akashgillella 2 жыл бұрын
Loved the tutorial
@denizural5390
@denizural5390 3 жыл бұрын
Great CMake playlist. I find it useful to open the verbosity via VERBOSE=1 when CMake complains. Then it is easier to debug.
@user-cc8kb
@user-cc8kb Жыл бұрын
Great tutorial! Thanks a lot :)
@PerfectHilton
@PerfectHilton 3 жыл бұрын
Exactly what i needed at the moment! Thanks
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Great to hear!
@tonywtyt
@tonywtyt 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 : )
@hosseinbeiranvand7169
@hosseinbeiranvand7169 3 жыл бұрын
very helpful! thanks!
@reinioyeah5467
@reinioyeah5467 3 жыл бұрын
Great tutorial 👍
@RobinDuckett
@RobinDuckett 2 жыл бұрын
I was laughing the entire time, saw you call the function in the header "adder" 🤣
@alex85907
@alex85907 3 жыл бұрын
Great Vid, learned a lot, thanks :)
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Glad it was helpful!
@sarthaksharma4816
@sarthaksharma4816 2 жыл бұрын
Thank you
@0xB16B00B
@0xB16B00B 3 жыл бұрын
Thank you very much...
@danielkurt7545
@danielkurt7545 Жыл бұрын
thank you best
@ELECTRONICWALKS24
@ELECTRONICWALKS24 2 жыл бұрын
thankyou!!!!!!!!!!!!
@hassannawazish9300
@hassannawazish9300 2 жыл бұрын
Thanks Man...........!
@carlosdalomba
@carlosdalomba 3 жыл бұрын
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 3 жыл бұрын
target_link_directories is indeed not needed here because the library is a subproject that cmake is building
@vladyslavtkach2209
@vladyslavtkach2209 3 жыл бұрын
Did you find out the difference between 2 and 3 so far?
@VuaTommy
@VuaTommy Ай бұрын
@@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
@aaaa1339
@aaaa1339 3 жыл бұрын
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.
@markharrington5826
@markharrington5826 3 жыл бұрын
These are very good tutorials Have made links to this and all others regarding CMake to Faceboook
@clintonreisig
@clintonreisig 2 жыл бұрын
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?
@leonardodavinci4259
@leonardodavinci4259 Жыл бұрын
Thanks! My Lord & Savior
@Pyrografpl
@Pyrografpl Жыл бұрын
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 🎉
@duckhe6143
@duckhe6143 Жыл бұрын
This is a very easy-understood tutorial. By the way, you definitely look like Zeus.
@beepst
@beepst Жыл бұрын
Aphex Twin teaches very good. :)
@catalinvoineag6344
@catalinvoineag6344 3 жыл бұрын
Very helpful, can you please put a link to the repository?
@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 жыл бұрын
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"?
@bieldozap
@bieldozap 4 жыл бұрын
nice
@yisuo1087
@yisuo1087 Жыл бұрын
actually all you need is add_subdirectory(Adder) # target_link_libraries( ... ... ...) target_link_libraries(${PROJECT_NAME} adder)
@Martin-yo8wh
@Martin-yo8wh 2 жыл бұрын
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?
@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?
@ErikBlueGuitar
@ErikBlueGuitar 2 жыл бұрын
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
@itsgalaxy2407
@itsgalaxy2407 3 жыл бұрын
nice! how about linking an external library next
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Yep that is next episode after this.
@h.hristov
@h.hristov 3 жыл бұрын
@@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 3 жыл бұрын
Checkout the Beginner/Intro CMake Course at www.udemy.com/course/master_cmake/?referralCode=D08DF343ABAE2835C3B7
@azazulhaque9375
@azazulhaque9375 Жыл бұрын
how can we link a static library to a main static library on which it has dependency using target_link_libraries ?
@Bananananamann
@Bananananamann 3 жыл бұрын
What do I get for my 2 Bonus points?
@X.A.N.A..
@X.A.N.A.. 2 жыл бұрын
How do you have sound effects in vscode?? It's cool
@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
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
Noted
@prajwaldeepkhokhar7416
@prajwaldeepkhokhar7416 2 жыл бұрын
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 2 жыл бұрын
It is made to detect it. I'm not sure of all the limitations, but the do have extensive documentation.
@kangzheng2067
@kangzheng2067 Жыл бұрын
hi, Tim what are the “public “ and “private “ used for?
@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
@naoryehuda6830
@naoryehuda6830 2 жыл бұрын
after running Cmake, why do you run make again, doesn't Cmake do it behind curtain?
@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?)
@Gloryisfood
@Gloryisfood 2 жыл бұрын
Is target_link_directories() not necessary that without the line the build should still pass?
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
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.
@nischalsehrawat2130
@nischalsehrawat2130 2 жыл бұрын
I think target_include_directories should be in the library not in the main CMakeLists.txt file
@tamasboros1798
@tamasboros1798 3 жыл бұрын
Do you always need to use "target_link_directories"? Or is it recommended? My example works without it.
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Generally only if it doesn't know where to find the link library.
@tamasboros1798
@tamasboros1798 3 жыл бұрын
@@CodeTechandTutorials Thank you!
@YourCRTube
@YourCRTube 3 жыл бұрын
@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 жыл бұрын
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 жыл бұрын
PS.: Or u need it, when u did the derping before xD
@squarerootof2
@squarerootof2 4 жыл бұрын
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.
@domagojbosnjak75
@domagojbosnjak75 3 жыл бұрын
2 points in the pocket
@twopie79
@twopie79 2 жыл бұрын
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
@guoliangwang4826
@guoliangwang4826 2 жыл бұрын
Great tutorials , but why your screen blurred?
@luojia4923
@luojia4923 9 ай бұрын
I felt confused, sad ~
@hanniballecter1734
@hanniballecter1734 3 жыл бұрын
How do you organize and build code that has both C and C++ in it?
@julienguay7524
@julienguay7524 3 жыл бұрын
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.
@amrtcpp6203
@amrtcpp6203 2 жыл бұрын
Can someone explain for me @15:33 , thanks
@masoodkamandy5370
@masoodkamandy5370 3 жыл бұрын
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 2 жыл бұрын
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 Жыл бұрын
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.
@amrtcpp6203
@amrtcpp6203 2 жыл бұрын
Please increase the microphone volume
@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.
@bu3778
@bu3778 Жыл бұрын
If Heisenberg did comp sci instead of chemistry
@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 2 жыл бұрын
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 ;)
@Popart-xh2fd
@Popart-xh2fd 4 ай бұрын
make not found!
@sadashivsahoo
@sadashivsahoo 3 жыл бұрын
How to get and link libatlas.so.3.1.2
@sadashivsahoo
@sadashivsahoo 3 жыл бұрын
In Ubuntu
@larsgustafsson215
@larsgustafsson215 Жыл бұрын
Thanks for a good tutorial, but Zeus is spelled Zeus.
@anshumanmajumdar7361
@anshumanmajumdar7361 3 жыл бұрын
Awesome tutorial series but the misspelled ZEUS is triggering my ocd lmao smh...
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Haha good stuff. Whoops didn't even notice.
@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
@recessiv3
@recessiv3 3 жыл бұрын
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
@CodeTechandTutorials
@CodeTechandTutorials 3 жыл бұрын
Yeah, I regret leaving that in there.
@Fareoneo
@Fareoneo 2 жыл бұрын
imagine doing a tutorial on something that you don't know how it works
@swengeer
@swengeer 7 ай бұрын
Informative video, but would be faster if you did all the typing, then simply discussed the results. Coding along is rather slow.
@corradosteri9150
@corradosteri9150 2 жыл бұрын
This video should be brought as an example on how not to make a tutorial. Confusing to say the least.
@TopConductor
@TopConductor Жыл бұрын
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.
@viktoriyamankovskaya5906
@viktoriyamankovskaya5906 2 жыл бұрын
i have a question: do u have a girlfriend?)
@CodeTechandTutorials
@CodeTechandTutorials 2 жыл бұрын
Certified Bachelor. (of the arts and tinder swipping)
@mydoghasschizophrenia
@mydoghasschizophrenia 2 жыл бұрын
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.
@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.
CMake Tutorial EP 3 | Git Submodules (adding glfw windowing library example)
21:51
Code, Tech, and Tutorials
Рет қаралды 83 М.
How-To Use C++ Libraries (without relying on a package manager)
30:22
Code, Tech, and Tutorials
Рет қаралды 52 М.
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 117 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 15 МЛН
Simplified CMake Tutorial
27:47
kandodev
Рет қаралды 113 М.
Minecraft Clone in C++ // Code Review
40:29
The Cherno
Рет қаралды 329 М.
CMake основы
12:46
S0ER
Рет қаралды 47 М.
Simulating the Evolution of Rock, Paper, Scissors
15:00
Primer
Рет қаралды 567 М.
CMake Tutorial EP 2 | Libraries | Installing | Pairing with Executables | RE-DONE!
36:48
How To Use VS CODE for C++ | With CMake & Any Compiler
9:14
Code, Tech, and Tutorials
Рет қаралды 72 М.
Introduction to Google Test and CMake
31:32
Rhymu's Videos
Рет қаралды 135 М.
What did I eat? 🤪😂 LeoNata Best #shorts
0:19
LeoNata Best
Рет қаралды 1,6 МЛН
devil Pk jesus 😱❤️😈#devil #jesus #shorts
0:15
Jesus Vs thank Devil
Рет қаралды 20 МЛН
What did I eat? 🤪😂 LeoNata Best #shorts
0:19
LeoNata Best
Рет қаралды 1,6 МЛН
Sweet watermelon 🍉😋
0:15
LizAlex Fam
Рет қаралды 8 МЛН