It took me forever to learn how the C pre-processor & build system works because hardly anyone covers them in detail in tutorials and you don't know that's the problem when you're a beginner. Every tutorial on C/C++ uses IDEs that hide these details (and generally don't circle back) which is fine if you're speed-running hello world, but not if you're trying to learn how to include other people's code you find online.
I've been working with modules lately and love it. Visual Studios support overall has been improving a lot, but they still have quirks, namely intellisense breaking here and there. Honestly though it is worth using if you can. I know the major compilers are still lacking so clearly it isn't feasible for everyone but definitely worth a try if you can.
Additionally, you could have added "Headers" to the visual studio 'additional include directories' in project settings, then just used the '#include "Timers.hpp"' etc.
Would have been nice to mention early on that C++ as of three years ago does also have modules you can import but that most libraries don't support them yet so you can mainly only use them for your own code.
It's not yet supported by all major compilers though, so that is going to be yet another headache until it is. I think it's currently only supported by the Microsoft compiler, so good luck getting it to work on Mac or Linux.
@@smokinglife8980 Better leave the internet then, the majority of it runs on Linux. Your phone runs either Android(Linux) or iOS. The only place where Windows dominates is PC.
Hi Cherno, I have watched many of your turtorials of cpp. I realy learned a lot from your videos, even more than how much teachers taught me in my college. Thank you very much
This video in general feels like a google search. I don't see why this video is tied to Visual Studio instead of just giving more generalized knowledge about how include directories work, I think there was some opportunities to save a lot of newer C++ developers from a lot of include errors, explaining recursive include error, explaining how you are not specifically required to include an `hpp` file or an `h and how actually in some cases it's a better practice to name them something else(.tpp). Also I feel like this misses some other stuff that doesn't necessarily have to do with include, but might still come up as a problem you might think is an include problem(inline functions, extern variables, etc.), another thing is including a header file that contains a template class, but having the function definitions separated in a different class, in that case you're required to instantiate the template in the file with the definitions. C++ in general has a lot of gotchas that might appear in an unexpected way. include is no different and the error messages are kind of cryptic, at least soon we might not have to deal with them as much with the addition of modules.
This channel is kind of weirdly tied to Visual Studio in alot of ways, even tools distributed by him generate visual studio files and solutions instead of a more traditional Make and Cmake approach
The thing which tripped me up the most with this was when including the same header on files on different locations when the path of the header wasn't added in the include paths
You can also just include different directories if you use different folders for source and header files. This make working a lot easier, where you don't always have to type "Headers/.." :)
Would it be so hard for Visual Studio to just scan all the files in my project and suggest the correct path like it already does for so many other languages? I think issues like these are IDE issues, not really language issues, but they frustrate people so much that they just switch languages instead for better IDE support.
I don't know how many people picked it up but I noticed you using "/" instead of the more tradition "\\" as a directory separator. I do it all the time as it saves a character and the \ is way over to the top right. PLUS it makes it UNIX compatible 🙂
Man I forgot just how horrible the visual studio filter stuff is in terms of getting in the way of obfuscating how stuff *actually* works. Excellent video.
In gcc you'd typically add an includes folder flag -I includes/ relative to which you would include your headers in a given source file. In CMake that would be done via target_include_directories or the like. Not sure about visual studio. Wouldn't touch that with a 10 ft pole.
The difference between #include "" and #include is actually not defined in the standard and varies slightly between compilers. In practice it is true that "" searches the cwd and does not but this is all by happy accident and not careful planning. What directories are searched and in what order is still up to the compiler implementers to decide.
Dude! I was trying to set up NeoVim for game development with SDL2 and ran into a black hole made of problems. I at least managed to get Neovim up and running on WSL but then I ran into the biggest problem, clangd (the plugin I was using to add diagnostics) needs a compile_commands.json file without it I get stupid errors saying "couldn't find include file" 😡 and no matter how hard I tried, I couldn't generate it. Just 5 minutes into this video and figured it out!!! 🥳 I just had to type the relative directory instead of the name of the file. Thanks a lot, man. 👍
LMAO. C has retarded preprocessor include directives too. So ancient and primitive. At least C++ is finally getting rid of them starting from C++20 by replacing them with holy modules.
Have you ever had a linking error in release but not in debug, where it can't find a library in release, but in debug it compiles just fine? What if the library it can't find in release is ?? I compared all the setting in VS2019 between release and debug and the libraries are the same. No idea where to look to figure this out
This is very probably because the include directories, between release and debug don't match, going to the project options and making sure they match may solve that. Also some times some projects, need different .libs for Release and Debug, for example release needs mylib.lib and debug needs mylibd.lib and you happen to be including the same lib for both compilation types.
Your project properties, which contain the include path settings, are different per each platform type. So when you change from debug to release, you actually have different project properties. What's happening is that in your release project properties you don't have the header folder path under the include setting.
my question is, how do you just disable the header folder in the solution explorer and make VS just put the file in the source files instead like it should be doing from the very begining?
Why is that my VScode and The cherno's VS code doesnot look similar?, a lot of options available in The cherno's C++ is not available in Visual Studio Code even though I have it up to date Can anyone help me as to why this is the case and how I can resolve it?
...or you could just use CLion, where it doesn't do this silly deceptive filter thing and actually mirrors the structure of your filesystem in the project. CLion is the only C++ IDE that I've not only found tolerable, but actually pleasant to use.
you could add the Headers directory to the include path of vs that you shown in the beginning in the project, i mean just to not have to write Headers each time you import something 😅
Which directory separator to use? Slash or antislash? Does it depend on your operating system? Because if that's the case, it means that if you send some code you wrote on windows (which uses backslashes) to a friend who uses a different os, he may not be able to compile your code.
Windows supports forward slash even though backslash is the native separator, so always use forward slash unless you want every Linux and Mac user to hate you
I never have these issue with headers. I honestly don't get how people do. With C++ you the programmer are supposed to know what you are doing. Could we make tools to include lots more stuff. Sure and it would either increase compile time at linking mostly or it would result in programs being bloated with more code that isn't used. I don't like either of those options. That said it would be easy to have the IDE search for that or give it a directory to look for those in. There are IDEs that do that code blocks allows you to do it for example. You can set such paths in your make files. It really isn't an issue with the language so much as either the tools you are using or lack of knowledge of that tool. Apparently you can set library paths in visual studio as well. You can set them up as a default. If you don't use them the compiler will just not include them at link time. Then you don't have to worry about it. You won't need to set it up every project you make and it will automatically be found.
any idea on how to do that? ucz after a few month of not coding in c++, my header files aren't just being recognized anymore, i even uinstalled all of the possible compilers since legacy and changed the include file path, its really grinding my gears
New to C++ and coding in general, I just wanted to say that this was the video that made classes click for me. Every video I've seen explains classes using people as an example, just creating like categories for age, height, weight, etc. I never understood the point. Seeing how the timer class is just structured functions within a broader shared category really did the trick. Also immediately showed me why using namespace std is bad.
Including a header file by it's path is not a practical solution. If you change the location of the header file you need to change how it is included in all places. The practical solution is to let the compiler know where to search for the header files with the -I option.
Yeah, that's not a fix for C++, that's a fix for Visual Studio. You should perhaps try to use a different environment yourself, like vim or emacs and use macros to handle compilation, maybe even learn how to write a Makefile.
It's all about Ukraine war, so if you can fix it it with these - do it, because I want to talk about what I would like to see and create a T-shirt that I wanted. So you don't want to deal with this connection string mess, you want install it and run it. I'm not rethinking how I fixed Ferrari in the past - what if I had that class diagram before. This is now as simple as PHP was, but try remember how it was with all the memory pointers and addresses. Don't you copy those rap songs in a radio you working now.
How To Fix Include Errors in Visual Studio != How To Fix Include Errors in C++. It would be helpful to change the title so your video finds the right audience.
@@anon_y_mousse it does with very minor changes / one reasonable google query. The main ideas behind the video 100% convert to other environments. The point about filters can be ignored (it's not central, take it as an extra "now you know"), and the thing about paths is shown in the VS's UI, but these are include paths which are a general concept - you can even use stuff like premake/cmake and they'll set this up the same way they would for other environments. The whole thing about what includes are, how they work, the role of the preprocessor, relative paths and include paths are valid c++, independent from VS.
@@user-sl6gn1ss8p In other words, not a generic solution. Talking about what the problem is doesn't solve the problem. Using a better, and more portable compiler would be at least better than the solution talked about in the video.
@@anon_y_mousse any c++ compiler/build system will have a slightly different way of doing the specific thing which is platform-specific in the video, but the reasoning behind them all will be the same. There's no magic solution in any of them: c++ includes work how they work, and the video explains that. I really don't get what your point is, there's no solution you couldn't be equally complaining about.
why you devs have to make all things so complex, have it function by default (settings) then have the basic settings clearly away from the super specific nonsense none ever uses
it needs to work by default with no settings adjusting, at optimum performance, the settings are only to alter the default, not to make it work when the defaults are trash
@@deltapi8859 1. Carbon doesn't exist yet. 2. Go is garbage collected, so its unusable for high performance programs. 3. Haskell is garbage collected, see point 2. 4. Rust is the only half-decent alternative. But generally rust took 99% of its ideas from C++. Writing modern C++ is very similar to writing rust.
True, damn, why not stop coding in general and use AI for everything? I think its now the age of assembly again. Lets go back to the roots and show everyone! Wuhuu!
Use what then? No language has a better ecosystem for game development than C++. There's all sorts of libraries and tools for it. Rust is simply not mature. Ada is meh. Zig is a kid. C is a disaster. And the Other languages are slow as a grandfather crossing the street.
Wouldn't mind an entire Visual Studio tutorial series. Should definitely do it!
Agreed. Sometimes I like to just start from scratch. I get dumber every year and need retraining.
Good idea!
That would be awesome
Please please please please
I think he already did a general one a long time ago.
It took me forever to learn how the C pre-processor & build system works because hardly anyone covers them in detail in tutorials and you don't know that's the problem when you're a beginner. Every tutorial on C/C++ uses IDEs that hide these details (and generally don't circle back) which is fine if you're speed-running hello world, but not if you're trying to learn how to include other people's code you find online.
Include errors are the nightmare of new C++ programmers. I remember banging my head on the table solving circular includes and compilation errors.
Also worth pointing out is that you can add the ./Headers directory to the include paths in project configuration.
This is indeed how I configure my cmake project.
I'd rather have the .cpp and .hpp equivalent files next to each other.
Didn't know the difference between and "" for the imports. Nice!
I've been working with modules lately and love it. Visual Studios support overall has been improving a lot, but they still have quirks, namely intellisense breaking here and there.
Honestly though it is worth using if you can. I know the major compilers are still lacking so clearly it isn't feasible for everyone but definitely worth a try if you can.
Additionally, you could have added "Headers" to the visual studio 'additional include directories' in project settings, then just used the '#include "Timers.hpp"' etc.
Would have been nice to mention early on that C++ as of three years ago does also have modules you can import but that most libraries don't support them yet so you can mainly only use them for your own code.
I used c++20 modules and I love them, except intellisense support is awful. But if you get past the annoying bits they're much easier to work with.
It's not yet supported by all major compilers though, so that is going to be yet another headache until it is. I think it's currently only supported by the Microsoft compiler, so good luck getting it to work on Mac or Linux.
@@smugtomato5972 good thing no one uses that shit
@@smokinglife8980 Better leave the internet then, the majority of it runs on Linux. Your phone runs either Android(Linux) or iOS. The only place where Windows dominates is PC.
@@smokinglife8980 What a stupid comment, lol.
Hi Cherno, I have watched many of your turtorials of cpp. I realy learned a lot from your videos, even more than how much teachers taught me in my college. Thank you very much
This video in general feels like a google search.
I don't see why this video is tied to Visual Studio instead of just giving more generalized knowledge about how include directories work, I think there was some opportunities to save a lot of newer C++ developers from a lot of include errors, explaining recursive include error, explaining how you are not specifically required to include an `hpp` file or an `h and how actually in some cases it's a better practice to name them something else(.tpp). Also I feel like this misses some other stuff that doesn't necessarily have to do with include, but might still come up as a problem you might think is an include problem(inline functions, extern variables, etc.), another thing is including a header file that contains a template class, but having the function definitions separated in a different class, in that case you're required to instantiate the template in the file with the definitions.
C++ in general has a lot of gotchas that might appear in an unexpected way. include is no different and the error messages are kind of cryptic, at least soon we might not have to deal with them as much with the addition of modules.
Great comment, tutorial with title "Fix your include errors in C++" definetly should have covered all this stuff
This channel is kind of weirdly tied to Visual Studio in alot of ways, even tools distributed by him generate visual studio files and solutions instead of a more traditional Make and Cmake approach
Hey you should make a video about the new import keyword and modules in c++20
You stole my name (?
The thing which tripped me up the most with this was when including the same header on files on different locations when the path of the header wasn't added in the include paths
You can also just include different directories if you use different folders for source and header files. This make working a lot easier, where you don't always have to type "Headers/.." :)
Would it be so hard for Visual Studio to just scan all the files in my project and suggest the correct path like it already does for so many other languages? I think issues like these are IDE issues, not really language issues, but they frustrate people so much that they just switch languages instead for better IDE support.
I don't know how many people picked it up but I noticed you using "/" instead of the more tradition "\\" as a directory separator. I do it all the time as it saves a character and the \ is way over to the top right. PLUS it makes it UNIX compatible 🙂
I thought you were going to talk about cyclic includes and dependency management with headers in C++. :)
Man I forgot just how horrible the visual studio filter stuff is in terms of getting in the way of obfuscating how stuff *actually* works. Excellent video.
could you drop a video about creating the hello triangle using different API's that can be changed at runtime ?
In gcc you'd typically add an includes folder flag -I includes/ relative to which you would include your headers in a given source file.
In CMake that would be done via target_include_directories or the like. Not sure about visual studio. Wouldn't touch that with a 10 ft pole.
The difference between #include "" and #include is actually not defined in the standard and varies slightly between compilers. In practice it is true that "" searches the cwd and does not but this is all by happy accident and not careful planning. What directories are searched and in what order is still up to the compiler implementers to decide.
could you make a video about c++20 modules and your opinion on its usefulness?
I not have C/C++, i have NMake, what need to do?
can I join your discord and have somebody look at why I'm getting an error 1 in a file?
As usual, your video is super useful and interesting, thanks a lot !
Dude! I was trying to set up NeoVim for game development with SDL2 and ran into a black hole made of problems. I at least managed to get Neovim up and running on WSL but then I ran into the biggest problem, clangd (the plugin I was using to add diagnostics) needs a compile_commands.json file without it I get stupid errors saying "couldn't find include file" 😡 and no matter how hard I tried, I couldn't generate it. Just 5 minutes into this video and figured it out!!! 🥳 I just had to type the relative directory instead of the name of the file. Thanks a lot, man. 👍
You can fix all errors in C++ by rewriting it in a real language like C
LMAO. C has retarded preprocessor include directives too. So ancient and primitive. At least C++ is finally getting rid of them starting from C++20 by replacing them with holy modules.
Are you going to put this in the c++ playlist?
Have you ever had a linking error in release but not in debug, where it can't find a library in release, but in debug it compiles just fine?
What if the library it can't find in release is ?? I compared all the setting in VS2019 between release and debug and the libraries are the same.
No idea where to look to figure this out
This is very probably because the include directories, between release and debug don't match, going to the project options and making sure they match may solve that. Also some times some projects, need different .libs for Release and Debug, for example release needs mylib.lib and debug needs mylibd.lib and you happen to be including the same lib for both compilation types.
Your project properties, which contain the include path settings, are different per each platform type. So when you change from debug to release, you actually have different project properties. What's happening is that in your release project properties you don't have the header folder path under the include setting.
These "filters" are a huge design flaw in Visual Studio. Microsoft should just get rid of them. Or at the very least not make them the default.
First time i see someone explaining clearly the difference between "" and weather on videos or forums. Who are you man ?
Cherno please make a course on C++ 😢
my question is, how do you just disable the header folder in the solution explorer and make VS just put the file in the source files instead like it should be doing from the very begining?
Still waiting for proper and easier support for modules in CMake and all (big 3) compilers 💀
We'll keep waiting until mid 2024 my bro ☠️
Need design patterns series in cpp. That would be awesome.
Why is that my VScode and The cherno's VS code doesnot look similar?, a lot of options available in The cherno's C++ is not available in Visual Studio Code even though I have it up to date
Can anyone help me as to why this is the case and how I can resolve it?
He is not using Visual Studio Code, he is using Visual Studio. They are two different things; the naming scheme can be confusing.
I don’t use visual studio but if I ever do this could save me a lot of trouble.
Cherno can you make a video about concepts in c++?
...or you could just use CLion, where it doesn't do this silly deceptive filter thing and actually mirrors the structure of your filesystem in the project. CLion is the only C++ IDE that I've not only found tolerable, but actually pleasant to use.
It is just a button and I am pretty sure you can keep it on be default. There are other reasons to use CLion, but this is a pretty weak one.
Can you make tutorials for Embarcadreo C++?
thought this would talk about CMake and that whole shabang cz usually linking hpp and cpp files is a pain
please do one for vscode
Is there anyone knows what theme Cherno uses is?
You should do a video on the new C++20 module system
Necesitaba este video hace 1 año y pico
you could add the Headers directory to the include path of vs that you shown in the beginning in the project, i mean just to not have to write Headers each time you import something 😅
Thank you, me too strugle a lot with file not found and because of this reason i stoped multiple projects including your open gl series
Can you do a video about the new modules in c++ and #embed macro
Why not just add Headers to your include directories?
Im getting hella include error with SFML + Imgui. First time C++ user coming from C
2:50 enunciation is so important
2:50 headaphiles? some one call mr. hansen
You said "header files" very quickly... and i was very confused for a second lmao
Which directory separator to use? Slash or antislash? Does it depend on your operating system?
Because if that's the case, it means that if you send some code you wrote on windows (which uses backslashes) to a friend who uses a different os, he may not be able to compile your code.
Windows supports forward slash even though backslash is the native separator, so always use forward slash unless you want every Linux and Mac user to hate you
AFAIK, you can always also just list the full path every time.
Great content. But it is more likely to be fix correct the error by changing setting in vs code
I never have these issue with headers. I honestly don't get how people do.
With C++ you the programmer are supposed to know what you are doing.
Could we make tools to include lots more stuff. Sure and it would either increase compile time at linking mostly or it would result in programs being bloated with more code that isn't used.
I don't like either of those options.
That said it would be easy to have the IDE search for that or give it a directory to look for those in. There are IDEs that do that code blocks allows you to do it for example.
You can set such paths in your make files.
It really isn't an issue with the language so much as either the tools you are using or lack of knowledge of that tool. Apparently you can set library paths in visual studio as well.
You can set them up as a default. If you don't use them the compiler will just not include them at link time.
Then you don't have to worry about it. You won't need to set it up every project you make and it will automatically be found.
any idea on how to do that? ucz after a few month of not coding in c++, my header files aren't just being recognized anymore, i even uinstalled all of the possible compilers since legacy and changed the include file path, its really grinding my gears
New to C++ and coding in general, I just wanted to say that this was the video that made classes click for me. Every video I've seen explains classes using people as an example, just creating like categories for age, height, weight, etc. I never understood the point. Seeing how the timer class is just structured functions within a broader shared category really did the trick. Also immediately showed me why using namespace std is bad.
2:50 oh boy an other youtuber doing videos on hedaphiles we get it okay some people are into ki-
Including a header file by it's path is not a practical solution. If you change the location of the header file you need to change how it is included in all places. The practical solution is to let the compiler know where to search for the header files with the -I option.
I literally, like, you know, couldn't, like, listen to, like, your, like video. Guess, like, why?
cannot wait to use c++20 modules...
Though buggy, modules are so much nicer
It's real detail.
Visual Studio devs making development 10 times harder than it should be while pretending to be helpful as usual.
👍Thanks.
Guys in hurry just watch last 13 second
This is just a window + visual studio overhead
I have no idea what i just watched. But cool 😂😂😂😂😂
bro this is c sharp not c ++
alternatively you can be programming on linux and avoid stupid problems like these
Yeah, that's not a fix for C++, that's a fix for Visual Studio. You should perhaps try to use a different environment yourself, like vim or emacs and use macros to handle compilation, maybe even learn how to write a Makefile.
U are the best
It's all about Ukraine war, so if you can fix it it with these - do it, because I want to talk about what I would like to see and create a T-shirt that I wanted. So you don't want to deal with this connection string mess, you want install it and run it. I'm not rethinking how I fixed Ferrari in the past - what if I had that class diagram before. This is now as simple as PHP was, but try remember how it was with all the memory pointers and addresses. Don't you copy those rap songs in a radio you working now.
How To Fix Include Errors in Visual Studio != How To Fix Include Errors in C++. It would be helpful to change the title so your video finds the right audience.
the bulk of the video works in other environments, you just have to know how dealing with include paths works on your own
@@user-sl6gn1ss8p In other words the video doesn't work for most people.
@@anon_y_mousse it does with very minor changes / one reasonable google query. The main ideas behind the video 100% convert to other environments.
The point about filters can be ignored (it's not central, take it as an extra "now you know"), and the thing about paths is shown in the VS's UI, but these are include paths which are a general concept - you can even use stuff like premake/cmake and they'll set this up the same way they would for other environments.
The whole thing about what includes are, how they work, the role of the preprocessor, relative paths and include paths are valid c++, independent from VS.
@@user-sl6gn1ss8p In other words, not a generic solution. Talking about what the problem is doesn't solve the problem. Using a better, and more portable compiler would be at least better than the solution talked about in the video.
@@anon_y_mousse any c++ compiler/build system will have a slightly different way of doing the specific thing which is platform-specific in the video, but the reasoning behind them all will be the same. There's no magic solution in any of them: c++ includes work how they work, and the video explains that. I really don't get what your point is, there's no solution you couldn't be equally complaining about.
cool
ks amak
why you devs have to make all things so complex, have it function by default (settings) then have the basic settings clearly away from the super specific nonsense none ever uses
it needs to work by default with no settings adjusting, at optimum performance, the settings are only to alter the default, not to make it work when the defaults are trash
and dev ide means that is has the optimal behaviour right away, no need to make the fork again for every project, meh man
like you want to make the dev more nuisance for some reason, ide/devs
your ide was to make things more manufacturable/devable, not make it a necessary nonsense setup duty
not a help, the dev ide is not enabling, its disabling, only in the way, better just do stuff by hand than to use the ide
The best way to solve include errors in C++ or any error in C++ is to wake up and start using Python.
the language that depends on C to be usable ? no, thanks
Funny. But C++20 solved this problem. It's just not implemented in GCC and Clang yet.
did you like windows 11, or you are ashamed of yourself?
"How to fix Include errors in C++" use a more modern language, problem solved.
Or use modules
@@razorgmyt6772 Tried that, didn't work. Still not properly implemented as of 2023
Use Carbon lmao
@@ohwow2074 carbon, rust. Anything. Hell even Go or Haskell.
@@deltapi8859 1. Carbon doesn't exist yet. 2. Go is garbage collected, so its unusable for high performance programs. 3. Haskell is garbage collected, see point 2. 4. Rust is the only half-decent alternative. But generally rust took 99% of its ideas from C++. Writing modern C++ is very similar to writing rust.
Here's an idea, STOP USING C++.
true, just write shit applications in javascript.
True, damn, why not stop coding in general and use AI for everything?
I think its now the age of assembly again. Lets go back to the roots and show everyone! Wuhuu!
Use what then? No language has a better ecosystem for game development than C++. There's all sorts of libraries and tools for it. Rust is simply not mature. Ada is meh. Zig is a kid. C is a disaster. And the Other languages are slow as a grandfather crossing the street.
Yeah lets write game engines in low-performance, high overhead GC languages. That should work great!
so you just moved it there and moved it back and you call it a logical fix?
The thumbnail already made me laugh
#include "IHateCpp.h"