在创建新文件时,其显示“< SFML / Graphics.hpp>”。没有这样的文件或目录” [英] On creation of a new file it shows "<SFML/Graphics.hpp> no such file or directory"

查看:855
本文介绍了在创建新文件时,其显示“< SFML / Graphics.hpp>”。没有这样的文件或目录”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我在代码块中创建一个新文件或类并包含Graphics标头或任何sfml标头时,编译器便说不出此类文件或目录。

Whenever I create a new file or class in code blocks and include Graphics header or any sfml header the compiler says no such file or directory.

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

When I work on a single file program works fine but when I create a new file and include the file in the same project then compiler starts showing errors.

它显示了此错误:


E:\codes\sfml_project\main.cpp:1:29:致命错误:SFML / Graphics.hpp:无此类文件或目录

E:\codes\sfml_project\main.cpp:1:29: fatal error: SFML/Graphics.hpp: No such file or directory

我什至尝试再次安装 SFML 2.1 并链接所有文件

I even tried installing SFML 2.1 again and linking all the files to CodeBlocks but it is of no use.

请帮帮我,我试图找出错误2天,但无法纠正。

Please help me out I have been trying to figure out the error for 2 days but couldn't correct it.

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

I first created the project in codeblocks which contains main.cpp file and code

    #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 ->代码块中的类,并包含文件SFML / Graphics.hpp

this works fine then i created a new class World and from file->new->class in codeblocks and included a file SFML/Graphics.hpp

World类看起来像

the World class looks like

World .hpp文件包含代码

World.hpp file contains code

    #ifndef WORLD_HPP
    #define WORLD_HPP

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

    #endif // WORLD_HPP

并且World.cpp文件包含

and World.cpp file contains

    #include "World.hpp"

    World::World()
    {
         //ctor
    }

这时只有编译器开始显示错误

at this point only the compiler starts showing error

E:\codes\sfml_project\World.hpp:4:29:致命错误:SFML / Graphics.hpp:没有此类文件或目录

E:\codes\sfml_project\World.hpp:4:29: fatal error: SFML/Graphics.hpp: No such file or directory

所有文件(World.hpp,World.cpp,main.cpp)都位于同一文件夹中。

And all the files ( World.hpp , World.cpp , main.cpp ) are in the same folder.

推荐答案

此外,尽管这似乎很愚蠢,但请确保还安装了dev软件包。

Additionally, though this may seem silly, make sure you've installed the dev package as well.

在基于debian的操作系统上是:
sudo apt-get install libsfml-dev

On a debian-based OS that is: sudo apt-get install libsfml-dev

它与SFML的其余部分不同。我碰到了同样的问题,那是我的疏忽。祝您编程愉快!

It's different from the rest of SFML. I bumped into the same issue, and that was my oversight. Happy coding!

这篇关于在创建新文件时,其显示“&lt; SFML / Graphics.hpp&gt;”。没有这样的文件或目录”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆