SFML community forums

Help => General => Topic started by: Niikhawod on February 15, 2013, 10:46:18 pm

Title: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 15, 2013, 10:46:18 pm
Hi,

I want to use sfml 2.0 with codeblocks 12.11 i have Cmake'd sfml from github and rebuild it in codeblocks, but i still get an error when i compile the basic program found in the first sfml 2.0 tutorial.

edit: i am using windows 7.
code i used.
#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;
}
 

Error i get.
Code: [Select]
G:\SFML\SFML-Base\main.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE'|
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 15, 2013, 11:40:54 pm
How are you linking SFML? Dynamic/static? debug/release? :)

Also please make use of the code=cpp tags, when posting code.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 15, 2013, 11:53:14 pm
How are you linking SFML? Dynamic/static? debug/release? :)

Also please make use of the code=cpp tags, when posting code.

i am linking dynamic libs and i am using release libs.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 16, 2013, 12:07:09 am
Then make sure that you're project settings are also set to release.

You can't mix debug and release modes!
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 16, 2013, 12:30:42 am
that made it worse  :-\

obj\Debug\main.o||In function `main':|
G:\SFML\SFML-Base\main.cpp|5|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE'
|
G:\SFML\SFML-Base\main.cpp|6|undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'|
G:\SFML\SFML-Base\main.cpp|7|undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
|
G:\SFML\SFML-Base\main.cpp|15|undefined reference to `_imp___ZN2sf6Window5closeEv'|
G:\SFML\SFML-Base\main.cpp|12|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
|
G:\SFML\SFML-Base\main.cpp|18|undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'|
G:\SFML\SFML-Base\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
|
G:\SFML\SFML-Base\main.cpp|19|undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
G:\SFML\SFML-Base\main.cpp|20|undefined reference to `_imp___ZN2sf6Window7displayEv'
|
G:\SFML\SFML-Base\main.cpp|9|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
obj\Debug\main.o||In function `ZN2sf11CircleShapeD1Ev'
:|
G:\SFML\SFML-Base\..\..\..\SFML-2.0-REBUILD\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'|
G:\SFML\SFML-Base\..\..\..\SFML-2.0-REBUILD\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZTVN2sf11CircleShapeE'
|
G:\SFML\SFML-Base\..\..\..\SFML-2.0-REBUILD\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `_imp___ZN2sf5ShapeD2Ev'|
||=== Build finished: 13 errors, 0 warnings (0 minutes, 0 seconds) ===|

Title: AW: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 16, 2013, 12:44:43 am
Make sure you link the libraries in the correct order.
You can remember it like this, sfml-graphics depends on sfml-window depends on sfml-system; so the order should be:

sfml-graphics
sfml-window
sfml-system
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 16, 2013, 01:00:02 am
I have setup everythjing like in the tutorial but for some reason it is not working anymore.

i have previosly compiled sfml 2.0 and that one worked but have stupidly deleted that one and now it doesn't work anymore :/.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Halsys on February 17, 2013, 02:02:51 am
Did you include everything(anything important*) in SFML's lib folder**- Under Linker settings?
Then include SFML's Include folder -under Search Directories under Compiler
Then do the same for SFML's lib folder -Under Linker(Next to Compiler)
Want me to post some pictures to help?

*You need Window,System,Graphics,Audio and maybe Network(If you want it)
**People Frown on this but it work for me... You don't have to do the SFML_STATIC OR DYNAMIC under #defines
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 17, 2013, 02:50:06 pm
i recompiled sfml and nog i am getting a different error when i compile and want to run the test program.

error i now get
(http://i.imgur.com/VK1lbUa.jpg)

linker
(http://i.imgur.com/Y6k87tS.jpg)

linker settings
(http://i.imgur.com/EgNnjXz.jpg)

compiler
(http://i.imgur.com/EgNnjXz.jpg)
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 17, 2013, 03:38:14 pm
How exactly did you compile SFML?
Make sure your compiler is setup correctly in Code::Blocks.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Niikhawod on February 17, 2013, 04:08:59 pm
i am using the default gnu gcc compiler settings in code::blocks.

Edit: i have recompiled sfml with a saperate MinGW32 - TDM compiler and now it is working again.  :-\
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Daddi on February 20, 2013, 06:04:53 pm
You could also download mingw from the official website and overrite Code::Blocks mingw folder. There are some differences between the compilers of each version.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 20, 2013, 06:14:57 pm
You could also download mingw from the official website and overrite Code::Blocks mingw folder.
Or rather download the Code::Blocks version without MinGW and set the compiler manually. ;)
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 22, 2013, 05:39:25 pm
Can you please post more precisely what you did to make it work? I wanted to move from my XP to my new 7 machine and I have the same error. I also followed the hint to have the right order. Didnt helped. Using the static libraries gives more undefined references. A question on stackoverflow couldn't helped me.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 23, 2013, 11:29:35 am
Maybe your installation is broken, but without specifc details it's impossible to tell
Just follow the official tutorial 1:1.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 01:24:17 pm
I followed the tutorial in the wiki by watching the video from SFMLCoder: http://www.youtube.com/watch?v=U1zN_QRSwxw. After trying it out several times I also write myself a batchscript. You can download it from www.joshua-behrens.de/index.php?page=post002 (http://www.joshua-behrens.de/?page=posts&index=1). I can also post the log(log deleted due to no errors.
Title: AW: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 23, 2013, 01:54:10 pm
Seems like everything built fine, so where's the problem?
For logs, you should only.post the parts with errors, which I couldn't find any, or over looked them. And no there is no spoiler tag or similar.

Btw. you should only follow the official tutorials. ;)
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 02:12:15 pm
I think this tutorial http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php is not good, because when I download the RC there is no subdirectory called branches. I just retried it and recognised if both path you have to give are the same, then there are the settings that are also in the pictures. Now it generated the makefiles fine. I'll try to make and test it.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Nexus on February 23, 2013, 02:15:28 pm
I think this tutorial http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php is not good, because when I download the RC there is no subdirectory called branches.
It doesn't say there is.

Apart from that, I have yet to see good video tutorials for SFML on Youtube. I don't know this specific one, but I have seen a lot of people with partial knowledge, especially when it comes to writing code.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 02:31:31 pm
In one of the images there are the two paths given for CMake and the first ist ./branches/sfml and the other ./build and they are both not in the archive whereas only the first must be given.

How far do I need to know how to code with SFML if it does not work (for me in Win 7)? I made a lot of (unfinished) things before with SFML on my XP netbook.

I must say at least it works with CMake to build this lib, but still giving the same error when linking.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Nexus on February 23, 2013, 02:39:32 pm
Ah, this is an old SVN version. But it doesn't matter, /branches/sfml2 is just the directory where you extract the SDK. Replace it with your own path.

Make sure you really don't have an old SFML version left or other things conflicting. Try to delete everything, download the SFML SDK and start again...
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 02:53:10 pm
I try to install SFML 2(I never worked with <=1.6) on this machine for the first time and I'm always re-unpack the downloaded archive (from yesterday) to restart.
Title: AW: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 23, 2013, 03:02:47 pm
It's not hard to build SFML with the latest snapshot directly from GitHub and following the official tutorial.
But you can also tale a look at my Nightly Builds. ;)
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 03:52:38 pm
That was a page that I should have found before. But I changed everything: I installed a mingw packet that your page uses, changed the toolchain to it, changed the compiler settings for the project, used the related libs that you compile (debug dynamic) and pressed recompile all. Still the same error undefined reference...
Title: AW: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on February 23, 2013, 03:56:03 pm
Well then give some specific errors.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on February 23, 2013, 04:00:31 pm
Everything the same the threadcreator posted (except the file path). I'm using his code, codeblocks 12.11, the mingw thats shipped with it(for testing your libs not) and that the VideoMode::ContexSettings are undefined referenced. I would also give you access via teamviewer to my machine to make it work :/ Or stream you what I do via skype or twitch.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Halsys on March 02, 2013, 10:27:59 am
Looking at this post again, You got some issues still... Some of them I think can be fixed and I notice a couple things I do differently compared to you.
I will note the step I do to get SFML working and the differences we have so you can take note of that.

To actually build your project with SFML and manage different system builds like mac and linux.
I make 2 types for each kind of systems... Debug and Release!
For each one I include the SFML Libs and Include folders.
Also Quick bro tip! Move a copy of SFML to your Project folder so you don't have to navigate across your system to include it! Very helpful tip is Helpful!
And when your programming on those systems you have to rebuild SFML every time and include it but at least you don't have to make a new project of your project!

Side Note:Under Compiler settings you can use more cores to build projects! I have 8 cores on my computer and I think I broke the sound barrier of my computer.... Where it would take 3mins... it takes less than 30 seconds!

If this doesn't help, I can make a video of me making SFML and building a simple project from the tutorial page on the SFML page... Explaining everything in a greater context. Would that help?
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on March 02, 2013, 10:47:45 pm
I just chose "Codeblocks MinGW", specified the c and c++ compiler and now I let it compile it with CB. It just took me 98 seconds. Maybe CB detects my cores automagically. But using the dll compiled via CB gives the same error. In my other project. For making it simple for me to use a external library I have a second folder for all the external libraries I download or test or whatelse and have it in the search directories for the compiler itself. I would be thankful for a video and thanks for the hint where the dlls are for cc1.exe, helped me a lot.
I see no reason why to put SFML in my projects directly.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: eXpl0it3r on March 03, 2013, 01:17:14 am
Well I didn't have a usable microphone at my disposal, so you'll have to go with the really crappy sound. ::)

I also forgot to show the part, where you add the compiler to the settings.
Go to Settings->Compiler...->Toolchain executables and add the path to MinGW there.

http://www.youtube.com/watch?v=5mbYYosHyYE

It's really quick and dirty, but it might give you an insight, at least that's what I'm hoping. ;)
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on March 03, 2013, 02:42:24 am
Well thank you exploiter,

at first I was quite confused that you have a German localization but you are speaking a quite good English to me so I wouldnt had identified you as a German-speaking person. I didn't anything different to you BUT I downloaded the 2.0RC from the downloadpage from sfml-dev.org and not from github and with the Codeblocks-project I testet the target "All" and the compiled binaries with my projects. Thanks for the video to show me the missing points. The release builds are working, but not the debug build. I tested with the code of the threadcreator. In debug target it's starting and throws a sigsev because window is 0 following the call stack:
#06E182A92sf::Window::Window(this=0x0)(C:\Users\User\Downloads\SFML-master\SFML-master\src\SFML\Window\Window.cpp:47)
#168ED61D1sf::RenderWindow::RenderWindow(this=0x0, mode=..., title=..., style=2686732, settings=...)(C:\Users\User\Downloads\SFML-master\SFML-master\src\SFML\Graphics\RenderWindow.cpp:42)
 
#2004014DFmain()(C:\Users\User\CBP\Test\main.cpp:5)
And looking at the comments in the code makes it clear why it is 0 but how to fix this without using the obvious one(adding the call to the base class constructor) because it is not advised?
#1:
/*44*/Window::Window() :
/*45*/m_impl          (NULL),
/*46*/m_context       (NULL),
/*47*/m_frameTimeLimit(Time::Zero)
/*48*/{
/*49*/
/*50*/}
#2:
/*42*/RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings)
/*43*/{
/*44*/    // Don't call the base class constructor because it contains virtual function calls
/*45*/    create(mode, title, style, settings);
/*46*/}
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: Steef435 on March 03, 2013, 05:10:32 pm
Just a long-shot: did you forget to include the Window module?
I had a problem like you today and I solved it like that.

I never had to include it before, I got this error since I updated my C::B and gcc.
Title: Re: CodeBlocks 12.11 SFML 2.0
Post by: JoshuaBehrens on March 03, 2013, 05:31:11 pm
It should be implemented by including Graphics. But well that was it. Debug and Release target are working. Thanks to all the people especially to Steef and Exploiter for their last hints that fixed it all.