![](/img/trans.png)
[英]Fatal error: SFML/Graphics.hpp: no such file or directory exists
[英]On creation of a new file it shows “<SFML/Graphics.hpp> no such file or directory”
每當我在代碼塊中創建新文件或類並包含Graphics頭文件或任何sfml頭文件時,編譯器都不會說此類文件或目錄。
當我處理單個文件程序時,效果很好,但是當我創建一個新文件並將該文件包含在同一項目中時,編譯器將開始顯示錯誤。
它顯示此錯誤:
E:\\ codes \\ sfml_project \\ main.cpp:1:29:致命錯誤:SFML / Graphics.hpp:沒有這樣的文件或目錄
我什至嘗試再次安裝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;
}
這工作正常,然后我在代碼塊中從文件-> new-> class創建了一個新類World,並包括了文件SFML / Graphics.hpp
世界一流的樣子
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:\\ codes \\ sfml_project \\ World.hpp:4:29:致命錯誤:SFML / Graphics.hpp:沒有這樣的文件或目錄
並且所有文件(World.hpp,World.cpp,main.cpp)都位於同一文件夾中。
另外,盡管這看起來很愚蠢,但請確保還安裝了dev軟件包。
在基於debian的操作系統上:sudo apt-get install libsfml-dev
它與SFML的其余部分不同。 我碰到了同樣的問題,那是我的疏忽。 編碼愉快!
您的編譯器似乎是GCC。 假設SFML/Graphics.hpp
確實在編譯器的include-search路徑中,那么您的問題是由編碼引起的:
#include < SFML/Graphics.hpp >
代替:
#include <SFML/Graphics.hpp>
尖括號必須包含要搜索的標題名稱,並且沒有其他內容。 如果它們圍住多余的空間,則多余的空間將被視為標頭名稱的一部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.