CodeBlocks中的SFML项目不起作用



codeBlocks版本:16.01SFML版本:2.4.2

我在CodeBlocks中创建了一个SFML 2.0项目。我选择了新的Project-> SFML Project-> 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:sfmlSFML-2.4.2lib -o binDebugaaa.exe
> objDebugmain.o   -lmingw32 -luser32 -lgdi32 -lwinmm -ldxguid
> C:sfmlSFML-2.4.2liblibsfml-graphics.a
> C:sfmlSFML-2.4.2liblibsfml-window.a
> C:sfmlSFML-2.4.2liblibsfml-system.a -lsfml-graphics-s-d
> -lsfml-window-s-d -lsfml-system-s-d -lsfml-main-d objDebugmain.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()' objDebugmain.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位版本,它起作用了。

相关内容

  • 没有找到相关文章

最新更新