Search code examples
c++visual-studio-2019glfwglad

#include not finding files while the Visual Studio autocomplete suggestions can find the files


I am trying to include Glad (generated from here with the GL3.3 api (having similar include problem with GLFW as well)) as such

#include <glad/glad.h>

I feel like this should work since I have my additional include directories for the file in the project as

vendor\Glad\include

where my VS solution has the file structure of

-solutionName
--projectName
---src
----projectname.h <- Where I am including from for now, latter I want to include from elsewhere under the src directory.
---vendor (same level as src)
----Glad
-----include
------glad
-------glad.h
------KHR
-------khrplatform.h

I have been able to get the include to work by including the file as

#include <../vendor/Glad/include/glad/glad.h>

but when I do this I get an error ("C1083" "Cannot open include file: 'KHR/khrplatform.h':No such file or directory") because an include in glad.h can't find khrplatform.h when it includes like so

#include <KHR/khrplatform.h>

I could change that line in glad.h but I really don't want to have to change a library's code to make mine work.

This also happens with GLFW which has mirroring additional include directories and file paths but with glad replaced with GLFW where applicable.

In addition Visual studio will offer the

<glad/glad.h>

file path as a suggestion when I am typing out the include line in projectName.h but I still get the error "C1083" "Cannot open include file: 'glad/glad.h': No such file or directory".

Another quirk is that I am using spdlog file the additional include directory

vendor\spdlog\include

and am able to include headers in the src directory as such:

#include <spdlog/spdlog.h>

which works and doesn't throw and problems.

The file structure for this is

-solutionName
--projectName
---src
----Utilities
-----Logger.h <- Where I am including from.
---vendor (same level as src)
----spdlog
-----include
------spdlog
-------spdlog.h <- file I am including just fine.

This makes it feel like only some of the additional include directories are actually working and I'm not sure why is this happening or how can I fix it after spending a couple hours playing guess and check. I want to include the libraries like

#include <glad/glad.h>
#include <GLFW/glfw3.h>

How can I make this work?

Thanks for your time, -Michael


Solution

  • Alright so I figured it out finally, I'm not happy with how I had to do it but I guess it works so I'll move on unless anyone has suggestions. So, the problem came down to that I was including the headers in a static lib I was making then used that static lib elsewhere. (I hadn't realized this was a problem otherwise I would have mentioned that in my original question, sorry everyone.) I included my lib by a header that includes all the dependencies that I want to have access to and later down the line these 3rd party static libs will git more and more abstracted but for the time being what I had to do was also tell my other "sandbox" (non library) project to also have additional include directories like

    $(SolutionDir)MyLibName\vendor\Glad\include
    

    and

    $(SolutionDir)MyLibName\vendor\GLFW\include
    

    Ideally I didn't want to include anything except MyLib but I guess this is my work around for now. Thank you to everyone who offered suggestions!