Search code examples
c++c++20visual-studio-2022gsl

how to use #include for GSL library in VS2022


how do I get VS2022 using C++20 to recognize the location of the GSL library ?

this line is working: #include"C:\Users\examples\libraries\GSL\include\gsl\algorithm"


but if I use this format instead: #include <gsl/algorithm>

in the Project Properties Page, Configuration Properties> C/C++> General: Additional Include Directories (is set to ) C:\Users\examples\libraries\GSL\include\gsl\

but that causes the following error. Error (active) E1696 cannot open source file "gsl/algorithm" C:\Users\examples\libraries\GSL\include\gsl

Am I putting the location of the 'algorithm' file in the wrong place in Project Properties Page ???

I do not know how to use the CMakeSettings.json or if there is a formal way to install this gsl folder ??? I am new to both VS2022 & C++20 and just copied the 'gsl' folder from an online source.


Solution

  • To fix, you should not be using the gsl portion in the Project Properties Page, Configuration Properties> C/C++> General: Additional Include Directories page. So:

    C:\Users\examples\libraries\GSL\include\gsl
    

    should be:

    C:\Users\examples\libraries\GSL\include
    

    This is so when you add the path plus the include file you end up with C:\Users\examples\libraries\GSL\include\gsl\algorithm instead of C:\Users\examples\libraries\GSL\include\gsl\gsl\algorithm.

    PS: I prefer using forward slashes for directories even on Windows as it avoids the extra mental overhead of remembering that they are not escape characters.