簡體   English   中英

代碼塊中的SFML項目不起作用

[英]SFML Project in Codeblocks does not work

代碼塊版本:16.01 SFML版本:2.4.2

我在Codeblocks中創建了SFML 2.0項目。 我選擇了“新建項目”->“ SFML項目”->“ SFML 2.0”。 我將此代碼復制到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;
}

構建代碼時,出現以下錯誤:

> -------------- Build: Debug in aaa (compiler: GNU GCC Compiler)---------------
> 
> mingw32-g++.exe -LC:\sfml\SFML-2.4.2\lib -o bin\Debug\aaa.exe
> obj\Debug\main.o   -lmingw32 -luser32 -lgdi32 -lwinmm -ldxguid
> C:\sfml\SFML-2.4.2\lib\libsfml-graphics.a
> C:\sfml\SFML-2.4.2\lib\libsfml-window.a
> C:\sfml\SFML-2.4.2\lib\libsfml-system.a -lsfml-graphics-s-d
> -lsfml-window-s-d -lsfml-system-s-d -lsfml-main-d obj\Debug\main.o: In function `main': C:/Users/my/Documents/codeblocks/aaa/main.cpp:5:
> undefined reference to `sf::String::String(char const*, std::locale
> const&)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:5: undefined
> reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int,
> unsigned int)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:5:
> undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode,
> sf::String const&, unsigned int, sf::ContextSettings const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:6: undefined reference
> to `sf::CircleShape::CircleShape(float, unsigned int)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:7: undefined reference
> to `sf::Color::Green' C:/Users/my/Documents/codeblocks/aaa/main.cpp:7:
> undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:15: undefined reference
> to `sf::Window::close()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:12: undefined reference
> to `sf::Window::pollEvent(sf::Event&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:18: undefined reference
> to `sf::Color::Color(unsigned char, unsigned char, unsigned char,
> unsigned char)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:18:
> undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:19: undefined reference
> to `sf::RenderStates::Default'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:19: undefined reference
> to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates
> const&)' C:/Users/my/Documents/codeblocks/aaa/main.cpp:20: undefined
> reference to `sf::Window::display()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:9: undefined reference
> to `sf::Window::isOpen() const'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:23: undefined reference
> to `sf::RenderWindow::~RenderWindow()'
> C:/Users/my/Documents/codeblocks/aaa/main.cpp:23: undefined reference
> to `sf::RenderWindow::~RenderWindow()' obj\Debug\main.o: In function
> `ZN2sf11CircleShapeD1Ev':
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `vtable for sf::CircleShape'
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `vtable for sf::CircleShape'
> C:/sfml/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp:41: undefined
> reference to `sf::Shape::~Shape()' collect2.exe: error: ld returned 1
> exit status Process terminated with status 1 (0 minute(s), 0
> second(s)) 20 error(s), 0 warning(s) (0 minute(s), 0 second(s))

我嘗試同時使用靜態和動態版本,但均未成功。 什么地方出了錯?

原來我使用的是錯誤版本的SFML。 我下載了GCC 4.7 TDM(SJLJ- 32位版本),它可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM