How To Fix Include Errors in C++

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • Patreon ► / thecherno
    Instagram ► / thecherno
    Twitter ► / thecherno
    Discord ► / discord
    Hazel ► hazelengine.com
    🕹️ Play our latest game FREE (made in Hazel!) ► studiocherno.i...
    🌏 Need web hosting? ► hostinger.com/...
    💰 Links to stuff I use:
    ⌨ Keyboard ► geni.us/T2J7
    🐭 Mouse ► geni.us/BuY7
    💻 Monitors ► geni.us/wZFSwSK

КОМЕНТАРІ • 142

  • @verminology9999
    @verminology9999 Рік тому +191

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

    • @glenneric1
      @glenneric1 Рік тому +16

      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 Рік тому +64

    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 Рік тому +8

    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 Рік тому +76

    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 Рік тому +14

    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.

  • @利丁
    @利丁 Рік тому +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

  • @octavio2895
    @octavio2895 Рік тому +13

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

  • @teksatan4699
    @teksatan4699 Рік тому +4

    Additionally, you could have added "Headers" to the visual studio 'additional include directories' in project settings, then just used the '#include "Timers.hpp"' etc.

  • @meem71
    @meem71 Рік тому +5

    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

  • @kebabimpaler
    @kebabimpaler Рік тому +4

    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.

  • @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 Рік тому +5

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

  • @whoopsimsorry2546
    @whoopsimsorry2546 Рік тому +11

    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 Рік тому +2

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

    • @TheAlexgoodlife
      @TheAlexgoodlife Рік тому +2

      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

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

  • @simonmaracine4721
    @simonmaracine4721 Рік тому +3

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

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

  • @bohdanvolokh3595
    @bohdanvolokh3595 Рік тому +1

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

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

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

  • @PoppsMadeThis
    @PoppsMadeThis Рік тому +1

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

  • @niki3352
    @niki3352 Рік тому +1

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

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

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

  • @harsh__dev
    @harsh__dev Рік тому +1

    Cherno please make a course on C++ 😢

  • @miguelandresa.m106
    @miguelandresa.m106 Рік тому

    Necesitaba este video hace 1 año y pico

  • @sundarrajn1003
    @sundarrajn1003 Рік тому +1

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

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

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

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

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

  • @prabhatgaurav5740
    @prabhatgaurav5740 Рік тому +4

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

  • @wjrasmussen666
    @wjrasmussen666 Рік тому +1

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

  • @vesk4000
    @vesk4000 Рік тому

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

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

  • @ramikassouf1822
    @ramikassouf1822 Рік тому

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

  • @neverknowsbest1717
    @neverknowsbest1717 8 місяців тому

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

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

  • @spicygaming9528
    @spicygaming9528 Рік тому

    Cherno can you make a video about concepts in c++?

  • @chastitywhiterose
    @chastitywhiterose Рік тому

    I don’t use visual studio but if I ever do this could save me a lot of trouble.

  • @mianmvlogs
    @mianmvlogs 29 днів тому +1

    please do one for vscode

  • @iamtimsson
    @iamtimsson 7 місяців тому

    2:50 headaphiles? some one call mr. hansen

  • @floatingpoint
    @floatingpoint Рік тому

    2:50 enunciation is so important

  • @Mhmhind
    @Mhmhind Рік тому

    Can you make tutorials for Embarcadreo C++?

  • @DimitryArsenev
    @DimitryArsenev Місяць тому

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

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

  • @KeithFox
    @KeithFox 3 місяці тому

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

  • @oleksijm
    @oleksijm Рік тому

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

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

  • @A-mf9pm
    @A-mf9pm 5 місяців тому

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

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

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

  • @iamtimsson
    @iamtimsson 7 місяців тому

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

  • @zxcaaq
    @zxcaaq Рік тому +1

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

  • @privacy-z4w
    @privacy-z4w 6 місяців тому +1

    Guys in hurry just watch last 13 second

  • @guilherme5094
    @guilherme5094 Рік тому

    👍Thanks.

  • @xeridea
    @xeridea Рік тому

    Why not just add Headers to your include directories?

  • @lzlxyz
    @lzlxyz Рік тому

    It's real detail.

  • @almighty1984
    @almighty1984 Рік тому

    Though buggy, modules are so much nicer

  • @videojeroki
    @videojeroki Рік тому

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

  • @lykuan8053
    @lykuan8053 Рік тому

    Is there anyone knows what theme Cherno uses is?

  • @spicygaming9528
    @spicygaming9528 Рік тому

    U are the best

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

  • @ikategame
    @ikategame Рік тому

    cool

  • @johnvonachen1672
    @johnvonachen1672 11 місяців тому

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

  • @sajjadjawadkadhim303
    @sajjadjawadkadhim303 Рік тому

    This is just a window + visual studio overhead

  • @merthyr1831
    @merthyr1831 Рік тому

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

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

  • @marscitizen42
    @marscitizen42 9 місяців тому

    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.

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

  • @Levi_scripts
    @Levi_scripts Місяць тому

    bro this is c sharp not c ++

  • @nasralkhteeb4362
    @nasralkhteeb4362 Рік тому

    ks amak

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

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

  • @AhmedAli-oe4oh
    @AhmedAli-oe4oh Рік тому

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

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

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