【发布时间】:2021-09-01 05:42:19
【问题描述】:
我的编译器在目录中搜索文件时出现问题。我在 Windows 10 上。
首先,我的文件是这样组织的:
- C:/mingw64/bin/g++(我的编译器在这里)
- C:/Users/Christophe/Documents/main.cpp(我的文件)
- C:/Users/Christophe/Documents/SFML/include (我的文件.hpp)
- C:/Users/Christophe/Documents/SFML/lib (???)
我有 9 个文件 .hpp,它们是:
- 音频.hpp
- 配置.hpp
- GpuPreference.hpp
- Graphics.hpp
- Main.hpp
- Network.hpp
- OpenGL.hpp
- System.hpp
- Window.hpp
我有我的 main.cpp,这是查看我的 SMFL 是否有效的示例:
#include <Graphics.hpp>
int main(){
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
问题是我的编译器说:“没有这样的文件或目录” #include
我试图通过 VisualStudioCode 在每个文件 .hpp 的 .json 中使用 IncludePaths 找到解决方案,但它不起作用。
我也试过在我的终端上输入一个命令:g++ -I/SFML/include main.cpp -o EX 但我有上面的错误。
或者:g++ -I/SFML/include/** main.cpp -o EX 但这次是红色的#include
我不明白他为什么会提出这个错误,因为我没有包含它......它似乎无法识别我的路径或在 .hpp 之间存在依赖关系。也许解决方案在目录“lib”中,但我不知道如何指定或操作它。
我从昨天开始就被屏蔽了,希望你能帮助我。
克里斯托夫。
【问题讨论】:
-
您的 -I 标志应该指向一个文件夹,例如 -I/SFML/include 您可能还希望在主目录中包含#include
。按照官方的 SFML 入门正确设置您的项目sfml-dev.org/tutorials/2.5 -
感谢您的回答。但是,这些教程涉及 Code::block 或旧版本的 VisualStudio。我没有他们的选择。我正在尝试制作一个“Makefile”来链接我的库。
标签: c++ compiler-errors directory dependencies