1

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

Welbog
  • 59,154
  • 9
  • 110
  • 123
Michael
  • 11
  • 7
  • Use *absolute* paths in your additional include directories. – n. m. could be an AI Dec 15 '20 at 08:19
  • I have replaced `vendor/Glad/include` with `D:\VSProjects\solutionName\ProjectName\vendor\Glad\include` applied changes and restarted VS and still got the same "C1083" error for glad/glad.h. – Michael Dec 15 '20 at 08:31
  • cannot see what's wrong, check for typos. BTW I think it would be better to build it as a separate project. If the files sit in your project directory, use VS macro `$(ProjectDir)` to represent it, not the real path. – n. m. could be an AI Dec 15 '20 at 08:50
  • Could you elaborate on what you mean when you say "I think it would be better to build it as a separate project." If you are referring to Glad then I think I might be as visual studio does build it the library into a .lib file and has the project as a dependency for the project I am trying to include the header in. I might be entirely off base and misunderstanding what you mean though! I have now added in the macro to all my additional include directory paths and it works until I try to include again. – Michael Dec 15 '20 at 08:59
  • So if it is a dependency, why do you put it in your project directory? It's not a part of your project. It's a separate project. – n. m. could be an AI Dec 15 '20 at 09:02
  • Mainly habit and ignorance of where I should stick it, I typically put all my external libraries I'm using in a folder called "vendor" in the project directory so Glad, GLFW, and spdlog are all in that vendor folder. – Michael Dec 15 '20 at 09:07

2 Answers2

0

Use "glad/glad.h" instead of <glad/glad.h>.

With the angle brackets the compiler searches only the standard paths for includes, with the quotation marks it also searches the additional include paths that you defined.

U. W.
  • 414
  • 2
  • 10
  • I've changed it so the include now reads `#include "glad/glad.h"` But get that same error "C1083" it does now not have the red error line under it though so it seems like progress. – Michael Dec 15 '20 at 08:11
  • Incorrect, the additional search path is used to search header files in both angle brackets and quotation marks. – n. m. could be an AI Dec 15 '20 at 08:15
  • Well, I have been wrong before... :-). It seems we need his complete list of additional include directories to further analyze this problem. – U. W. Dec 15 '20 at 08:21
  • Update: nevermind about the red error underline disappearing it is now back after reloading Visual studio. – Michael Dec 15 '20 at 08:21
  • Here is my complete list of additional include directories: "src" "vendor\spdlog\include" "vendor\GLFW\include" "vendor\Glad\include" – Michael Dec 15 '20 at 08:23
0

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!

Michael
  • 11
  • 7
  • Well, even if you hide all these include files in another include file, at least the compiler has to know where all your include files are located, otherwise how can the compiler find them? – U. W. Dec 16 '20 at 08:04
  • That would make sense to me if the place I had to add the include directories wasn't a separate project from the one I am `#including` them in. From what I understand they should only get compiled into the static lib I am linking them into not the driver I am testing the lib with. – Michael Dec 16 '20 at 08:32