创建新文件时,它显示"<SFML/Graphics.hpp> no such file or directory"

On creation of a new file it shows "<SFML/Graphics.hpp> no such file or directory"

本文关键字:gt hpp Graphics no such directory or file SFML 新文件 文件      更新时间:2023-10-16

每当我在代码块中创建新文件或类并包含Graphics头或任何sfml头时,编译器都会说没有这样的文件或目录。

当我在单个文件程序上工作时工作正常,但当我创建一个新文件并将该文件包含在同一个项目中时,编译器开始显示错误。

显示如下错误:

E:codessfml_projectmain.cpp:1:29:致命错误:SFML/Graphics.hpp: No such file or directory

我甚至尝试再次安装SFML 2.1并将所有文件链接到CodeBlocks,但这是没有用的。

请帮帮我,我已经试着找出这个错误2天了,但无法纠正。

我首先在代码块中创建了项目,其中包含main.cpp文件和代码

    #include < SFML/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;
   }

这个工作得很好,然后我在代码块中创建了一个新的类World和从file->new->class,并包含了一个文件SFML/Graphics.hpp

the World class looks like

World.hpp文件包含代码

    #ifndef WORLD_HPP
    #define WORLD_HPP
    #include < SFML/Graphics.hpp >
    class World
    {
        public:
        World();
        protected:
        private:
    };
    #endif // WORLD_HPP

和World.cpp文件包含

    #include "World.hpp"
    World::World()
    {
         //ctor
    }
此时只有编译器开始显示错误

E:codessfml_projectWorld.hpp:4:29:致命错误:SFML/Graphics.hpp: No such file or directory

所有的文件(World.hpp, World.cpp, main.cpp)都在同一个文件夹中

另外,尽管这看起来很傻,但请确保您已经安装了开发包。

在基于debian的操作系统中为:安装libsfml-dev

它与SFML的其余部分不同。我遇到了同样的问题,这是我的疏忽。编码快乐!

您的编译器显示为GCC。假设SFML/Graphics.hpp确实在编译器的包含搜索路径,那么您的问题就来自于编码:

#include < SFML/Graphics.hpp >

代替:

#include <SFML/Graphics.hpp>

尖括号必须包含要搜索的header-name,没有别的了。如果他们把剩余空间围起来,那么剩余