How To Fix Include Errors in C++

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 144

  • @verminology9999
    @verminology9999 Год назад +204

    Wouldn't mind an entire Visual Studio tutorial series. Should definitely do it!

    • @glenneric1
      @glenneric1 Год назад +17

      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 Год назад +71

    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.

  • @DarioCorno
    @DarioCorno Год назад +12

    Include errors are the nightmare of new C++ programmers. I remember banging my head on the table solving circular includes and compilation errors.

  • @MrRaylith
    @MrRaylith Год назад +78

    Also worth pointing out is that you can add the ./Headers directory to the include paths in project configuration.

    • @MelroyvandenBerg
      @MelroyvandenBerg Год назад +5

      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.

  • @octaviotastico
    @octaviotastico Год назад +15

    Didn't know the difference between and "" for the imports. Nice!

  • @ChrisCarlos64
    @ChrisCarlos64 Год назад +5

    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 Год назад +5

    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 Год назад +9

    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 Год назад +3

      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 Год назад +2

      ​@@smugtomato5972 good thing no one uses that shit

    • @smugtomato5972
      @smugtomato5972 Год назад +6

      @@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.

  • @利丁
    @利丁 Год назад +2

    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

  • @whoopsimsorry2546
    @whoopsimsorry2546 Год назад +12

    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 Год назад +3

      Great comment, tutorial with title "Fix your include errors in C++" definetly should have covered all this stuff

    • @TheAlexgoodlife
      @TheAlexgoodlife Год назад +3

      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

  • @octavio2895
    @octavio2895 Год назад +13

    Hey you should make a video about the new import keyword and modules in c++20

  • @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

  • @TheJerry2912
    @TheJerry2912 2 месяца назад

    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/.." :)

  • @lake5044
    @lake5044 Год назад +4

    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.

  • @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 🙂

  • @simonmaracine4721
    @simonmaracine4721 Год назад +3

    I thought you were going to talk about cyclic includes and dependency management with headers in C++. :)

  • @kebabimpaler
    @kebabimpaler Год назад +5

    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.

  • @PoppsMadeThis
    @PoppsMadeThis Год назад +1

    could you drop a video about creating the hello triangle using different API's that can be changed at runtime ?

  • @nextlifeonearth
    @nextlifeonearth Год назад +10

    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.

  • @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.

  • @niki3352
    @niki3352 Год назад +1

    could you make a video about c++20 modules and your opinion on its usefulness?

  • @DimitryArsenev
    @DimitryArsenev 5 месяцев назад

    I not have C/C++, i have NMake, what need to do?

  • @KeithFox
    @KeithFox 7 месяцев назад

    can I join your discord and have somebody look at why I'm getting an error 1 in a file?

  • @bohdanvolokh3595
    @bohdanvolokh3595 Год назад +1

    As usual, your video is super useful and interesting, thanks a lot !

  • @NeoRender
    @NeoRender Месяц назад

    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. 👍

  • @Maicowerk
    @Maicowerk Год назад +2

    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.

  • @wjrasmussen666
    @wjrasmussen666 Год назад +1

    Are you going to put this in the c++ playlist?

  • @SergeyBerengard
    @SergeyBerengard Год назад +1

    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 Год назад +1

      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.

  • @zdspider6778
    @zdspider6778 Год назад +1

    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.

  • @Byynx
    @Byynx Год назад

    First time i see someone explaining clearly the difference between "" and weather on videos or forums. Who are you man ?

  • @harsh__dev
    @harsh__dev Год назад +1

    Cherno please make a course on C++ 😢

  • @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?

  • @furuthebat
    @furuthebat Год назад +3

    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 ☠️

  • @sundarrajn1003
    @sundarrajn1003 Год назад +1

    Need design patterns series in cpp. That would be awesome.

  • @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.

  • @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++?

  • @vorpal22
    @vorpal22 Год назад +1

    ...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 Год назад +1

      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.

  • @Mhmhind
    @Mhmhind Год назад

    Can you make tutorials for Embarcadreo C++?

  • @ramikassouf1822
    @ramikassouf1822 Год назад

    thought this would talk about CMake and that whole shabang cz usually linking hpp and cpp files is a pain

  • @mianmvlogs
    @mianmvlogs 4 месяца назад +1

    please do one for vscode

  • @lykuan8053
    @lykuan8053 Год назад

    Is there anyone knows what theme Cherno uses is?

  • @vesk4000
    @vesk4000 Год назад

    You should do a video on the new C++20 module system

  • @miguelandresa.m106
    @miguelandresa.m106 Год назад

    Necesitaba este video hace 1 año y pico

  • @yassine-sa
    @yassine-sa Год назад

    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 😅

  • @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

  • @zxcaaq
    @zxcaaq Год назад +1

    Can you do a video about the new modules in c++ and #embed macro

  • @xeridea
    @xeridea Год назад

    Why not just add Headers to your include directories?

  • @MrSomethingdark
    @MrSomethingdark 2 месяца назад

    Im getting hella include error with SFML + Imgui. First time C++ user coming from C

  • @floatingpoint
    @floatingpoint Год назад

    2:50 enunciation is so important

  • @iamtimsson
    @iamtimsson 11 месяцев назад

    2:50 headaphiles? some one call mr. hansen

  • @neverknowsbest1717
    @neverknowsbest1717 Год назад

    You said "header files" very quickly... and i was very confused for a second lmao

  • @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 Год назад +4

      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

  • @oleksijm
    @oleksijm Год назад

    AFAIK, you can always also just list the full path every time.

  • @prabhatgaurav5740
    @prabhatgaurav5740 Год назад +4

    Great content. But it is more likely to be fix correct the error by changing setting in vs code

  • @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 Год назад

      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

  • @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.

  • @iamtimsson
    @iamtimsson 11 месяцев назад

    2:50 oh boy an other youtuber doing videos on hedaphiles we get it okay some people are into ki-

  • @martinchekurov5726
    @martinchekurov5726 Год назад +1

    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.

  • @johnvonachen1672
    @johnvonachen1672 Год назад

    I literally, like, you know, couldn't, like, listen to, like, your, like video. Guess, like, why?

  • @videojeroki
    @videojeroki Год назад

    cannot wait to use c++20 modules...

  • @almighty1984
    @almighty1984 Год назад

    Though buggy, modules are so much nicer

  • @MKmk-w9k
    @MKmk-w9k Год назад

    It's real detail.

  • @merthyr1831
    @merthyr1831 Год назад

    Visual Studio devs making development 10 times harder than it should be while pretending to be helpful as usual.

  • @guilherme5094
    @guilherme5094 Год назад

    👍Thanks.

  • @privacy-z4w
    @privacy-z4w 10 месяцев назад +1

    Guys in hurry just watch last 13 second

  • @sajjadjawadkadhim303
    @sajjadjawadkadhim303 Год назад

    This is just a window + visual studio overhead

  • @A-mf9pm
    @A-mf9pm 9 месяцев назад

    I have no idea what i just watched. But cool 😂😂😂😂😂

  • @Levi_scripts
    @Levi_scripts 5 месяцев назад

    bro this is c sharp not c ++

  • @marscitizen42
    @marscitizen42 Год назад

    alternatively you can be programming on linux and avoid stupid problems like these

  • @anon_y_mousse
    @anon_y_mousse Год назад +1

    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.

  • @spicygaming9528
    @spicygaming9528 Год назад

    U are the best

  • @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.

  • @not_ever
    @not_ever Год назад +4

    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 Год назад +1

      @@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 Год назад +1

      @@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.

  • @ikategame
    @ikategame Год назад

    cool

  • @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

  • @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 Год назад +2

      the language that depends on C to be usable ? no, thanks

    • @ohwow2074
      @ohwow2074 Год назад +1

      Funny. But C++20 solved this problem. It's just not implemented in GCC and Clang yet.

  • @AhmedAli-oe4oh
    @AhmedAli-oe4oh Год назад

    did you like windows 11, or you are ashamed of yourself?

  • @deltapi8859
    @deltapi8859 Год назад +2

    "How to fix Include errors in C++" use a more modern language, problem solved.

    • @razorgmyt6772
      @razorgmyt6772 Год назад +2

      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.

  • @Lucretia9000
    @Lucretia9000 Год назад +1

    Here's an idea, STOP USING C++.

    • @DANIEL-mh2ef
      @DANIEL-mh2ef Год назад +7

      true, just write shit applications in javascript.

    • @BlackxesWasTaken
      @BlackxesWasTaken Год назад +1

      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 Год назад +1

    The thumbnail already made me laugh
    #include "IHateCpp.h"