I made a project that is using SFML library on linux, it's working pretty fine. I start it by launching this script exec.sh:
g++ -c main.cpp -I/usr/include
g++ main.o -o sfml-app -L/usr/lib -lsfml-graphics -lsfml-window -lsfml-system
export LD_LIBRARY_PATH=/usr/lib && ./sfml-app
And here is the code de in the main.cpp file:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Blue);
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;
}
But the problem is that i can't debug it and i always have an error when trying it. Can someone give me an advice or explain how can i properly do it? I need the solution exactly for linux, i'm a newbie in this OC and IDE.
Here's the ERROR, after debugging using g++:
Starting build...
Build finished with error:
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `main':
/home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:6: undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Color::Blue'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:7: undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:15: undefined reference to `sf::Window::close()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:18: undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:19: undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:20: undefined reference to `sf::Window::display()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /home/yashmerino/Desktop/Developing/testsfml 1 file/main.cpp:5: undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: /tmp/ccnkqRHk.o: in function `sf::CircleShape::~CircleShape()':
/usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `vtable for sf::CircleShape'
/usr/bin/ld: /usr/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status
Try installing library to your system path. For Arch based Linux -
sudo pacman -S sfml
For Debian based Linux -
sudo apt-get install sfml-dev
And just use following g++ command -
g++ -c main.cpp -o main.o
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
It is better to use a IDE for it. You can use
Code Blocks
Code Lite
Apache netbeans
Eclipse
And if you are familiar with cmake you can use-
Kdevelop