VS2017下OpenGL C++项目头文件多错误求助
Fixing Your OpenGL Project Compile Errors in VS2017
Hey there, let's work through these two compile issues step by step—since you're a C++ beginner diving into LearnOpenGL, I know these little roadblocks can feel pretty frustrating. Let's break them down:
1. Error: "name followed by '::' must be a class or namespace it is in (FileSystem::getPath)"
This error means your compiler doesn't recognize FileSystem as a valid class or namespace when it tries to resolve FileSystem::getPath. Here's what to check:
- Double-check the filesystem.h inclusion: Make sure you've added
#include "filesystem.h"at the top of your main.cpp, and that the filesystem.h file is actually in your project directory (or in a folder VS is set to look for headers). - Verify the FileSystem namespace/class: Open up filesystem.h and confirm there's a properly declared
namespace FileSystemthat contains thegetPathfunction. Typos happen—maybe it's spelledFileSysinstead ofFileSystem, or the function is named differently? - Check project include paths: If filesystem.h is in a subfolder (like
utils/), you need to either use#include "utils/filesystem.h"or add that subfolder to your project's include directories. To do this in VS2017:- Right-click your project in Solution Explorer → Properties
- Go to Configuration Properties → C/C++ → General
- Add the folder path to Additional Include Directories
2. Error: Cannot open source file "root_directory.h"
Even after downloading the file, the compiler can't find it—here's how to fix that:
- Place root_directory.h in the right spot: Either put it in the same folder as filesystem.h, or in a folder that's already in your project's include paths.
- Fix the include statement in filesystem.h: If filesystem.h uses
#include <root_directory.h>(angle brackets), change it to#include "root_directory.h"(double quotes). Angle brackets tell the compiler to look in system library paths, while double quotes prioritize your project's local directories. - Add the file's folder to include paths: If you keep root_directory.h in a separate folder, add that folder to your project's Additional Include Directories using the same steps as above.
- Check for filename typos: Make sure the downloaded file is named exactly
root_directory.h(no extra spaces, wrong capitalization—Windows is case-insensitive, but it's still good practice to match what the header expects).
Quick Extra Tip for VS2017
Since LearnOpenGL relies on modern C++ features, make sure your project is set to use C++17 or later:
- Right-click your project → Properties
- Go to Configuration Properties → C/C++ → Language
- Set C++ Standard to ISO C17 Standard (/std:c17)
That should get you past these two errors. Let me know if you hit any other snags!
内容的提问来源于stack exchange,提问作者Miki
相关产品推荐
相关产品推荐

