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).
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
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!
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
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.
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
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
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.
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).
@@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
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 : )
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?
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.
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?
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 🎉
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.
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?)
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.
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?
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 }
@@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.
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.
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
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!
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.
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.
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.
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?
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
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.
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.
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!
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?
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.
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).
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
Those extra commands are exactly what I needed to know how to do. So its a good intro example imo.
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!
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
Very good tutorial! The errors/fixes are so helpful because it mimics development.
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.
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
True, I tested with that too
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
What undergrad teaches this?
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.
You are really OURLORDANDSAVIOR! Thank you so much for this videos!!!
Best cmake education I’ve had yet
Very nice tutorial covering lots of information in a beginner friendly way. Thanks!
It was very useful. Just what i needed at the moment. Thanks so much.
You absolute legend! Thanks so much for this tutorial, man.
best cmake series on the tubes
Got two points to my overall score. Now I have two
I love you for this series, help a lot
love the desktop sound effects
Thank for good feature covering. You really safe a lot of time
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).
target_link_directories is indeed not needed here because the library is a subproject that cmake is building
Did you find out the difference between 2 and 3 so far?
@@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
I was laughing the entire time, saw you call the function in the header "adder" 🤣
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 : )
CMake Episode 2: Attack of the typos :) thanks for the vid bro, makes all this feel less scary
Keep making more videos! Love your videos!
Great CMake playlist. I find it useful to open the verbosity via VERBOSE=1 when CMake complains. Then it is easier to debug.
actually all you need is
add_subdirectory(Adder)
# target_link_libraries( ... ... ...)
target_link_libraries(${PROJECT_NAME} adder)
Good stuff, I really enjoy the tutorials!
Awesome, thank you!
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?
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.
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?
how can we link a static library to a main static library on which it has dependency using target_link_libraries ?
hi, Tim what are the “public “ and “private “ used for?
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?
How do you have sound effects in vscode?? It's cool
Thanks for these introduction videos!
Loved the tutorial
Thanks for the tutorials :D
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 🎉
Is target_link_directories() not necessary that without the line the build should still pass?
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.
love the desktop adorable sound effects!!!!!! How to change that?? Would you mind also give a tutorial on that, sir?
Thanks. The sounds come with MX Linux, the OS I was using here. I believe it was in the sound options.
Does it matter what order you enter .cpp files into the "add_executable"?
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?)
It is made to detect it. I'm not sure of all the limitations, but the do have extensive documentation.
Very helpful, can you please put a link to the repository?
Do you always need to use "target_link_directories"? Or is it recommended? My example works without it.
Generally only if it doesn't know where to find the link library.
@@CodeTechandTutorials Thank you!
@Brown Smith In this case it is not needed, because the lib is a subproject (a "target") and cmake knows all about it, literally.
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.
PS.: Or u need it, when u did the derping before xD
Great tutorial! Thanks a lot :)
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?
Nvm I was too hasty lmao
Can someone explain for me @15:33 , thanks
How would you use cmake to include a directory full of libraries you want access to in main?
for instance a folder containing two other libraries (adder and subtractor?)
Exactly what i needed at the moment! Thanks
Great to hear!
after running Cmake, why do you run make again,
doesn't Cmake do it behind curtain?
Great Vid, learned a lot, thanks :)
Glad it was helpful!
What do I get for my 2 Bonus points?
This is a very easy-understood tutorial. By the way, you definitely look like Zeus.
I think target_include_directories should be in the library not in the main CMakeLists.txt file
nice! how about linking an external library next
Yep that is next episode after this.
@@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
Checkout the Beginner/Intro CMake Course at www.udemy.com/course/master_cmake/?referralCode=D08DF343ABAE2835C3B7
Thanks for your tutorial. Very helpful.
Great tutorials , but why your screen blurred?
How do you organize and build code that has both C and C++ in it?
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
}
@@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.
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.
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.
Love the vids, very helpful stuff!
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
Noted
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!
You can just compile it as a static library and you do not need a main
Great tutorial 👍
Do you need both target_link_directories and target_link_libraries? Also great content, thank you!
target_link_directories is not needed
Thanks! My Lord & Savior
These are very good tutorials Have made links to this and all others regarding CMake to Faceboook
Aphex Twin teaches very good. :)
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?
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.
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.
I did CMake the first one, but normally I just use qmake & QT.
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.
Thank you very much...
Please increase the microphone volume
How to get and link libatlas.so.3.1.2
In Ubuntu
very helpful! thanks!
Thank you
thank you best
thankyou!!!!!!!!!!!!
Thanks Man...........!
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?
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 ;)
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
2 points in the pocket
make not found!
I felt confused, sad ~
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
Yeah, I regret leaving that in there.
If Heisenberg did comp sci instead of chemistry
Thanks for a good tutorial, but Zeus is spelled Zeus.
Awesome tutorial series but the misspelled ZEUS is triggering my ocd lmao smh...
Haha good stuff. Whoops didn't even notice.
nice
Informative video, but would be faster if you did all the typing, then simply discussed the results. Coding along is rather slow.
This video should be brought as an example on how not to make a tutorial. Confusing to say the least.
imagine doing a tutorial on something that you don't know how it works
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.
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.
i have a question: do u have a girlfriend?)
Certified Bachelor. (of the arts and tinder swipping)
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!
It's cool that you have found some better tools and methods. Care to share?
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?
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.