How To Fix Include Errors in C++

  Рет қаралды 91,584

The Cherno

The Cherno

Күн бұрын

Пікірлер: 142
@verminology9999
@verminology9999 Жыл бұрын
Wouldn't mind an entire Visual Studio tutorial series. Should definitely do it!
@glenneric1
@glenneric1 Жыл бұрын
Agreed. Sometimes I like to just start from scratch. I get dumber every year and need retraining.
@skyseed3005
@skyseed3005 Жыл бұрын
Good idea!
@b0xb0x87
@b0xb0x87 Жыл бұрын
That would be awesome
@SchlangeBob
@SchlangeBob Жыл бұрын
Please please please please
@mhanna7878
@mhanna7878 Жыл бұрын
I think he already did a general one a long time ago.
@xankersmith9194
@xankersmith9194 Жыл бұрын
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.
@MrRaylith
@MrRaylith Жыл бұрын
Also worth pointing out is that you can add the ./Headers directory to the include paths in project configuration.
@MelroyvandenBerg
@MelroyvandenBerg Жыл бұрын
This is indeed how I configure my cmake project.
@Juke172
@Juke172 Жыл бұрын
I'd rather have the .cpp and .hpp equivalent files next to each other.
@DarioCorno
@DarioCorno Жыл бұрын
Include errors are the nightmare of new C++ programmers. I remember banging my head on the table solving circular includes and compilation errors.
@octaviotastico
@octaviotastico Жыл бұрын
Didn't know the difference between and "" for the imports. Nice!
@ChrisCarlos64
@ChrisCarlos64 Жыл бұрын
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.
@teksatan4699
@teksatan4699 Жыл бұрын
Additionally, you could have added "Headers" to the visual studio 'additional include directories' in project settings, then just used the '#include "Timers.hpp"' etc.
@sinom
@sinom Жыл бұрын
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.
@KarimInordinate
@KarimInordinate Жыл бұрын
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.
@smugtomato5972
@smugtomato5972 Жыл бұрын
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
@smokinglife8980 Жыл бұрын
​@@smugtomato5972 good thing no one uses that shit
@smugtomato5972
@smugtomato5972 Жыл бұрын
@@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.
@josh1234567892
@josh1234567892 Жыл бұрын
@@smokinglife8980 What a stupid comment, lol.
@meem71
@meem71 Жыл бұрын
The worst part is when you are you trying to include header file, typing name of this file, intellisense shows it, but later intelli says "no", no this file doesnt exists
@octavio2895
@octavio2895 Жыл бұрын
Hey you should make a video about the new import keyword and modules in c++20
@octaviotastico
@octaviotastico Жыл бұрын
You stole my name (?
@whoopsimsorry2546
@whoopsimsorry2546 Жыл бұрын
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.
@lysy-zn2gg
@lysy-zn2gg Жыл бұрын
Great comment, tutorial with title "Fix your include errors in C++" definetly should have covered all this stuff
@TheAlexgoodlife
@TheAlexgoodlife Жыл бұрын
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
@利丁
@利丁 Жыл бұрын
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
@spudgossie
@spudgossie Жыл бұрын
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 🙂
@user-sl6gn1ss8p
@user-sl6gn1ss8p Жыл бұрын
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
@nextlifeonearth
@nextlifeonearth Жыл бұрын
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.
@simonmaracine4721
@simonmaracine4721 Жыл бұрын
I thought you were going to talk about cyclic includes and dependency management with headers in C++. :)
@rickr530
@rickr530 Жыл бұрын
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.
@kebabimpaler
@kebabimpaler Жыл бұрын
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.
@Byynx
@Byynx Жыл бұрын
First time i see someone explaining clearly the difference between "" and weather on videos or forums. Who are you man ?
@lake5044
@lake5044 Жыл бұрын
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.
@PoppsMadeThis
@PoppsMadeThis Жыл бұрын
could you drop a video about creating the hello triangle using different API's that can be changed at runtime ?
@wjrasmussen666
@wjrasmussen666 Жыл бұрын
Are you going to put this in the c++ playlist?
@Maicowerk
@Maicowerk Жыл бұрын
You can fix all errors in C++ by rewriting it in a real language like C
@ohwow2074
@ohwow2074 Жыл бұрын
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.
@vorpal22
@vorpal22 Жыл бұрын
...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.
@heh_boaner
@heh_boaner Жыл бұрын
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.
@niki3352
@niki3352 Жыл бұрын
could you make a video about c++20 modules and your opinion on its usefulness?
@furuthebat
@furuthebat Жыл бұрын
Still waiting for proper and easier support for modules in CMake and all (big 3) compilers 💀
@ohwow2074
@ohwow2074 Жыл бұрын
We'll keep waiting until mid 2024 my bro ☠️
@bohdanvolokh3595
@bohdanvolokh3595 Жыл бұрын
As usual, your video is super useful and interesting, thanks a lot !
@zdspider6778
@zdspider6778 Жыл бұрын
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.
@nexby323
@nexby323 Жыл бұрын
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
@sundarrajn1003
@sundarrajn1003 Жыл бұрын
Need design patterns series in cpp. That would be awesome.
@harsh__dev
@harsh__dev Жыл бұрын
Cherno please make a course on C++ 😢
@Tacos4brekky
@Tacos4brekky Жыл бұрын
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.
@SergeyBerengard
@SergeyBerengard Жыл бұрын
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
@Argoon1981
@Argoon1981 Жыл бұрын
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.
@human-ft3wk
@human-ft3wk Жыл бұрын
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.
@yassinesafraoui
@yassinesafraoui Жыл бұрын
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 😅
@vesk4000
@vesk4000 Жыл бұрын
You should do a video on the new C++20 module system
@neverknowsbest1717
@neverknowsbest1717 8 ай бұрын
You said "header files" very quickly... and i was very confused for a second lmao
@ramikassouf1822
@ramikassouf1822 Жыл бұрын
thought this would talk about CMake and that whole shabang cz usually linking hpp and cpp files is a pain
@miguelandresa.m106
@miguelandresa.m106 Жыл бұрын
Necesitaba este video hace 1 año y pico
@prabhatgaurav5740
@prabhatgaurav5740 Жыл бұрын
Great content. But it is more likely to be fix correct the error by changing setting in vs code
@chastitywhiterose
@chastitywhiterose Жыл бұрын
I don’t use visual studio but if I ever do this could save me a lot of trouble.
@spicygaming9528
@spicygaming9528 Жыл бұрын
Cherno can you make a video about concepts in c++?
@KeithFox
@KeithFox 4 ай бұрын
can I join your discord and have somebody look at why I'm getting an error 1 in a file?
@mianmvlogs
@mianmvlogs Ай бұрын
please do one for vscode
@diconicabastion5790
@diconicabastion5790 Жыл бұрын
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.
@limsiryuean5040
@limsiryuean5040 10 ай бұрын
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
@SiontheRapadant
@SiontheRapadant Жыл бұрын
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?
@Mhmhind
@Mhmhind Жыл бұрын
Can you make tutorials for Embarcadreo C++?
@oleksijm
@oleksijm Жыл бұрын
AFAIK, you can always also just list the full path every time.
@iamtimsson
@iamtimsson 7 ай бұрын
2:50 headaphiles? some one call mr. hansen
@martinchekurov5726
@martinchekurov5726 Жыл бұрын
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.
@floatingpoint
@floatingpoint Жыл бұрын
2:50 enunciation is so important
@5cover
@5cover Жыл бұрын
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.
@smugtomato5972
@smugtomato5972 Жыл бұрын
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
@DimitryArsenev
@DimitryArsenev Ай бұрын
I not have C/C++, i have NMake, what need to do?
@harshithgowda6227
@harshithgowda6227 Жыл бұрын
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?
@tappyoka7496
@tappyoka7496 Жыл бұрын
He is not using Visual Studio Code, he is using Visual Studio. They are two different things; the naming scheme can be confusing.
@xeridea
@xeridea Жыл бұрын
Why not just add Headers to your include directories?
@lzlxyz
@lzlxyz Жыл бұрын
It's real detail.
@iamtimsson
@iamtimsson 7 ай бұрын
2:50 oh boy an other youtuber doing videos on hedaphiles we get it okay some people are into ki-
@lykuan8053
@lykuan8053 Жыл бұрын
Is there anyone knows what theme Cherno uses is?
@almighty1984
@almighty1984 Жыл бұрын
Though buggy, modules are so much nicer
@zxcaaq
@zxcaaq Жыл бұрын
Can you do a video about the new modules in c++ and #embed macro
@videojeroki
@videojeroki Жыл бұрын
cannot wait to use c++20 modules...
@privacy-z4w
@privacy-z4w 6 ай бұрын
Guys in hurry just watch last 13 second
@merthyr1831
@merthyr1831 Жыл бұрын
Visual Studio devs making development 10 times harder than it should be while pretending to be helpful as usual.
@A-mf9pm
@A-mf9pm 6 ай бұрын
I have no idea what i just watched. But cool 😂😂😂😂😂
@sajjadjawadkadhim303
@sajjadjawadkadhim303 Жыл бұрын
This is just a window + visual studio overhead
@marscitizen42
@marscitizen42 9 ай бұрын
alternatively you can be programming on linux and avoid stupid problems like these
@guilherme5094
@guilherme5094 Жыл бұрын
👍Thanks.
@johnvonachen1672
@johnvonachen1672 11 ай бұрын
I literally, like, you know, couldn't, like, listen to, like, your, like video. Guess, like, why?
@anon_y_mousse
@anon_y_mousse Жыл бұрын
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.
@Netryon
@Netryon Жыл бұрын
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.
@ikategame
@ikategame Жыл бұрын
cool
@Levi_scripts
@Levi_scripts Ай бұрын
bro this is c sharp not c ++
@spicygaming9528
@spicygaming9528 Жыл бұрын
U are the best
@not_ever
@not_ever Жыл бұрын
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.
@user-sl6gn1ss8p
@user-sl6gn1ss8p Жыл бұрын
the bulk of the video works in other environments, you just have to know how dealing with include paths works on your own
@anon_y_mousse
@anon_y_mousse Жыл бұрын
@@user-sl6gn1ss8p In other words the video doesn't work for most people.
@user-sl6gn1ss8p
@user-sl6gn1ss8p Жыл бұрын
@@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.
@anon_y_mousse
@anon_y_mousse Жыл бұрын
@@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.
@user-sl6gn1ss8p
@user-sl6gn1ss8p Жыл бұрын
@@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.
@ridhwaanany7480
@ridhwaanany7480 Жыл бұрын
The best way to solve include errors in C++ or any error in C++ is to wake up and start using Python.
@razorgmyt6772
@razorgmyt6772 Жыл бұрын
the language that depends on C to be usable ? no, thanks
@ohwow2074
@ohwow2074 Жыл бұрын
Funny. But C++20 solved this problem. It's just not implemented in GCC and Clang yet.
@nasralkhteeb4362
@nasralkhteeb4362 Жыл бұрын
ks amak
@Jkauppa
@Jkauppa Жыл бұрын
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
@Jkauppa
@Jkauppa Жыл бұрын
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
@Jkauppa
@Jkauppa Жыл бұрын
and dev ide means that is has the optimal behaviour right away, no need to make the fork again for every project, meh man
@Jkauppa
@Jkauppa Жыл бұрын
like you want to make the dev more nuisance for some reason, ide/devs
@Jkauppa
@Jkauppa Жыл бұрын
your ide was to make things more manufacturable/devable, not make it a necessary nonsense setup duty
@Jkauppa
@Jkauppa Жыл бұрын
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
@deltapi8859
@deltapi8859 Жыл бұрын
"How to fix Include errors in C++" use a more modern language, problem solved.
@razorgmyt6772
@razorgmyt6772 Жыл бұрын
Or use modules
@deltapi8859
@deltapi8859 Жыл бұрын
@@razorgmyt6772 Tried that, didn't work. Still not properly implemented as of 2023
@ohwow2074
@ohwow2074 Жыл бұрын
Use Carbon lmao
@deltapi8859
@deltapi8859 Жыл бұрын
@@ohwow2074 carbon, rust. Anything. Hell even Go or Haskell.
@lucass8119
@lucass8119 Жыл бұрын
@@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.
@AhmedAli-oe4oh
@AhmedAli-oe4oh Жыл бұрын
did you like windows 11, or you are ashamed of yourself?
@Lucretia9000
@Lucretia9000 Жыл бұрын
Here's an idea, STOP USING C++.
@DANIEL-mh2ef
@DANIEL-mh2ef Жыл бұрын
true, just write shit applications in javascript.
@BlackxesWasTaken
@BlackxesWasTaken Жыл бұрын
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!
@ohwow2074
@ohwow2074 Жыл бұрын
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.
@lucass8119
@lucass8119 Жыл бұрын
Yeah lets write game engines in low-performance, high overhead GC languages. That should work great!
@Coding-to4zj
@Coding-to4zj Жыл бұрын
so you just moved it there and moved it back and you call it a logical fix?
@_prothegee
@_prothegee Жыл бұрын
The thumbnail already made me laugh #include "IHateCpp.h"
BEST WAY to read and understand code
17:24
The Cherno
Рет қаралды 160 М.
BETTER Header Files and Preprocessor Debugging
24:26
The Cherno
Рет қаралды 72 М.
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
How I Turned a Lolipop Into A New One 🤯🍭
00:19
Wian
Рет қаралды 10 МЛН
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 28 МЛН
why do header files even exist?
10:53
Low Level
Рет қаралды 414 М.
Stop using std::vector wrong
23:14
The Cherno
Рет қаралды 105 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 797 М.
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 176 М.
"Hello, World" in 5 CURSED languages that no one should use
13:08
Dreams of Code
Рет қаралды 536 М.
SOME UNIQUE C++ CODE! // Pacman Clone Code Review
26:42
The Cherno
Рет қаралды 277 М.
you need to stop using print debugging (do THIS instead)
7:07
Low Level
Рет қаралды 438 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 94 М.
Using AI to help me with C++
24:31
The Cherno
Рет қаралды 110 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel (kiwi)
Рет қаралды 196 М.