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

Author Topic: Can't get SFML working in Code::Blocks  (Read 1740 times)

0 Members and 1 Guest are viewing this topic.

luitzen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Can't get SFML working in Code::Blocks
« on: January 29, 2018, 10:31:32 pm »
I can't get SFML working in Code::Blocks.

I'm using Code::Blocks 16.01. I used the tutorial (https://www.sfml-dev.org/tutorials/2.4/start-cb.php).

Installation directory: C:\SFML-2.4.2

Project >> Build Options has:
- Project name:
-- Search directories >> Compiler: C:\SFML-2.4.2\include
-- Search directories >> Linker: C:\SFML-2.4.2\lib
- Debug:
-- Linker settings:
--- sfml-graphics-d
--- sfml-window-d
--- sfml-system-d
- Release:
-- Linker settings:
--- sfml-graphics
--- sfml-window
--- sfml-system

I used the following test code (how do I format code on this forum?):

#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;
}

When I try to build the project, I get the following errors:
-------------- Build: Release in First SFML (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\SFML-2.4.2\lib -o "bin\Release\First SFML.exe" obj\Release\main.o  -s  -lsfml-graphics -lsfml-window -lsfml-system
obj\Release\main.o:main.cpp:(.text.startup+0xc5): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
obj\Release\main.o:main.cpp:(.text.startup+0xf5): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
obj\Release\main.o:main.cpp:(.text.startup+0xed): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
obj\Release\main.o:main.cpp:(.text.startup+0x12e): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
obj\Release\main.o:main.cpp:(.text.startup+0x133): undefined reference to `_imp___ZN2sf5Color5GreenE'
obj\Release\main.o:main.cpp:(.text.startup+0x14f): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
obj\Release\main.o:main.cpp:(.text.startup+0x172): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
obj\Release\main.o:main.cpp:(.text.startup+0x1a9): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
obj\Release\main.o:main.cpp:(.text.startup+0x1db): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
obj\Release\main.o:main.cpp:(.text.startup+0x1f3): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
obj\Release\main.o:main.cpp:(.text.startup+0x1f8): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
obj\Release\main.o:main.cpp:(.text.startup+0x214): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
obj\Release\main.o:main.cpp:(.text.startup+0x223): undefined reference to `_imp___ZN2sf6Window7displayEv'
obj\Release\main.o:main.cpp:(.text.startup+0x242): undefined reference to `_imp___ZN2sf6Window5closeEv'
obj\Release\main.o:main.cpp:(.text.startup+0x24c): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
obj\Release\main.o:main.cpp:(.text.startup+0x274): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x28a): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x302): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
obj\Release\main.o:main.cpp:(.text.startup+0x32a): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
obj\Release\main.o:main.cpp:(.text.startup+0x340): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
21 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
« Last Edit: January 29, 2018, 10:36:37 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't get SFML working in Code::Blocks
« Reply #1 on: January 29, 2018, 10:35:51 pm »
What SFML version did you download?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

luitzen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Can't get SFML working in Code::Blocks
« Reply #2 on: January 30, 2018, 12:39:09 am »
I used the SJLJ version (64-bit), but then I tried the 32 bit version and it did work. I compiled the source, copied the dlls to the folder with the exe, but when I try to execute the exe I get the error message "Cannot find access point of Procedure _ZSt24_throw_out_of_range_fmtPKcz in DLL file (path)\sfml_system-2.dll" (translated from Dutch).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't get SFML working in Code::Blocks
« Reply #3 on: January 30, 2018, 12:58:04 am »
Yeah, I guessed you probably used the 64-bit version.

So you really are using the compiler that came with Code::Blocks 16? And you're not using the 17 release from December, because that one isn't compatible with the provided binaries.

Where did you copy the runtime libraries from?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

luitzen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Can't get SFML working in Code::Blocks
« Reply #4 on: January 30, 2018, 01:17:42 am »
Since I was moving around different versions of SFML I realized that might cause a problem. So what I did is I went to the install directory of SFML again and copied the dlls from the bin directory there.

Running the exe from Code::Blocks seems to work though.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't get SFML working in Code::Blocks
« Reply #5 on: January 30, 2018, 07:04:58 am »
You also need to copy the runtime libraries from MinGW's bin directory (see tutorial).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

luitzen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Can't get SFML working in Code::Blocks
« Reply #6 on: January 30, 2018, 12:07:12 pm »
Thanks, it's working now.

I did not find the mentioned instructions in the tutorial though, so I copied all dlls. Could you give a link to a tutorial that gives more information on that topic?

luitzen

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Can't get SFML working in Code::Blocks
« Reply #7 on: February 02, 2018, 03:11:57 pm »
Which DLL files do I need to copy from the compiler folder and which one can I leave out?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't get SFML working in Code::Blocks
« Reply #8 on: February 02, 2018, 03:23:12 pm »
If you start your application from the explorer without having any version of the needed DLLs in PATH, it will tell you which one it expects.

Usually you'll have to provide libstdc++... libgcc... and if you use MinGW-w64 with POSIX threading you'll also need libwinpthread...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/