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

狂风中的少年 提交于 2019-12-11 14:49:52

问题


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.

It is showing this error:

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

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

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

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;
   }

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

the World class looks like

World.hpp file contains code

    #ifndef WORLD_HPP
    #define WORLD_HPP

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

    #endif // WORLD_HPP

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: fatal error: SFML/Graphics.hpp: No such file or directory

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


回答1:


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

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

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




回答2:


Your compiler appears to be GCC. Assuming that SFML/Graphics.hpp is indeed in the compiler's include-search paths, then your problem results from coding:

#include < SFML/Graphics.hpp >

instead of:

#include <SFML/Graphics.hpp>

The angle-brackets must enclose the header-name to be searched for, and nothing else. If they enclose surplus spaces then the surplus spaces are taken to be part of the header name.



来源:https://stackoverflow.com/questions/24218348/on-creation-of-a-new-file-it-shows-sfml-graphics-hpp-no-such-file-or-director

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!