0
代码块版本:16.01 SFML版本:2.4.2SFML项目代码块不起作用
我创建的代码块的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))
我试图用静态和动态的版本没有任何成功。什么地方出了错?
可能重复[什么是未定义的引用/无法解析的外部符号错误,我该如何解决它?](https://stackoverflow.com /问题/ 12573816 /什么 - 是 - 一 - 未定义参考悬而未决,外部符号错误和如何-DO-修复) – alseether