Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking error with codeblocks (windows)  (Read 1177 times)

0 Members and 1 Guest are viewing this topic.

biitse

  • Newbie
  • *
  • Posts: 2
    • View Profile
Linking error with codeblocks (windows)
« on: January 21, 2020, 12:21:18 am »
Im fairly new to programming so forgive me if I missed something obvious.

Im trying to compile this program from the tutorial
Quote
#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;
}


This is the error I get when codeblocks compiles:
Quote
-------------- Build: Debug in hello (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe  -o bin\Debug\hello.exe obj\Debug\main.o  -lsfml-graphics -lsfml-window -lsfml-system 
obj\Debug\main.o: In function `main':
C:/Users/~/~/~/~/~/~/hello/main.cpp:9: undefined reference to `sf::Window::isOpen() const'
C:/Users/~/~/~/~/~/~/hello/main.cpp:12: undefined reference to `sf::Window::pollEvent(sf::Event&)'
collect2.exe: error: ld returned 1 exit status

What's strange to me is that it only gives me errors about sf::Window functions, which Im guessing is in lsfml-window.

Also, if I compile in command prompt with this:
Quote
g++ main.cpp -o hello -lsfml-graphics -lsfml-window -lsfml-system
Then I get no linking errors and I get a working .exe

« Last Edit: January 21, 2020, 12:24:32 am by biitse »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Linking error with codeblocks (windows)
« Reply #1 on: January 21, 2020, 05:38:49 pm »
Given that the object file is located in the Debug directory, I assume it was built in debug mode (-g), as such you also need to link the debug SFML libraries, with the suffix -d
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

biitse

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Linking error with codeblocks (windows)
« Reply #2 on: January 21, 2020, 06:27:51 pm »
Given that the object file is located in the Debug directory, I assume it was built in debug mode (-g), as such you also need to link the debug SFML libraries, with the suffix -d

Okay, I just switched from debug to release and it compiled and ran perfectly. thank you :)