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

Author Topic: Undefined references with CodeBlocks and MinGW  (Read 10454 times)

0 Members and 1 Guest are viewing this topic.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Undefined references with CodeBlocks and MinGW
« on: December 19, 2013, 08:37:21 am »
I'm compiling the lastest SFML (commit 4a30054) from source with MinGW which goes fine (I guess -- I get .a files) for use in CodeBlocks (CB). When I attempt to build the project in CB I get several hundred "undefined reference" errors. For example:

Code: [Select]
..\..\libs\SFML-master-build\lib/libsfml-graphics-s-d.a(RenderWindow.cpp.obj): In function `ZNK2sf12RenderWindow7captureEv':
E:/Dev/libs/SFML-master/src/SFML/Graphics/RenderWindow.cpp:92: undefined reference to `glReadPixels@28'
..\..\libs\SFML-master-build\lib/libsfml-graphics-s-d.a(RenderTarget.cpp.obj): In function `ZN2sf12RenderTarget5clearERKNS_5ColorE':
E:/Dev/libs/SFML-master/src/SFML/Graphics/RenderTarget.cpp:61: undefined reference to `glClearColor@16'
E:/Dev/libs/SFML-master/src/SFML/Graphics/RenderTarget.cpp:62: undefined reference to `glClear@4'


I'm following the CMake tutorial when compiling SFML. When I hit the configure button this is my output:

Code: [Select]
The C compiler identification is GNU 4.7.2
The CXX compiler identification is GNU 4.7.2
Check for working C compiler: C:/MinGW/bin/gcc.exe
Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/MinGW/bin/g++.exe
Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Looking for sys/types.h
Looking for sys/types.h - found
Looking for stdint.h
Looking for stdint.h - found
Looking for stddef.h
Looking for stddef.h - found
Check size of void*
Check size of void* - done
Found OpenGL: opengl32 
Found Freetype: E:/Dev/libs/SFML-master/extlibs/libs-mingw/x86/libfreetype.a (found version "2.4.4")
Found GLEW: E:/Dev/libs/SFML-master/extlibs/libs-mingw/x86/libglew.a 
Found JPEG: E:/Dev/libs/SFML-master/extlibs/libs-mingw/x86/libjpeg.a 
Found OpenAL: E:/Dev/libs/SFML-master/extlibs/libs-mingw/x86/libopenal32.a 
Found SNDFILE: E:/Dev/libs/SFML-master/extlibs/libs-mingw/x86/libsndfile.a 
Configuring done
Generating done

I generate the makefiles and then build SFML with MinGW Make via the command line. I've also tried compiling with GCC 4.6.2 with the same result.

Once I have SFML compiled I'm using the CodeBlocks tutorial to set up a project and build it. When I try to build I get the errors mentioned above. For completeness this the code I have in main.cpp (straight from the tutorial):

Code: [Select]
#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;
}

Based on the error it seems to me that the extlibs shipped with SFML are not getting compiled into the .a files. I've downloaded the MinGW version of SFML 2.1 from the site and the libsfml-graphics-s-d.a file is 3915KB on my computer while the one I compiled from source is 2526KB which would indicate that the official one has something I'm missing.

When I update my project to point to the official libs downloaded from the SFML site my project builds and runs as expected.

I'm not an expert in CMake/C++ but I was able to successfully compile SFML from source around the time 2.0 was released so I know my system can compile SFML correctly.

Does anyone have any idea what I'm doing wrong?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
Re: Undefined references with CodeBlocks and MinGW
« Reply #1 on: December 19, 2013, 09:06:18 am »
Since you're using the latest version from GitHub, you'll need to know some of the changes, which are not yet documented in the tutorials. The change you've issues with is, that dependencies now won't get included into the SFML libraries, but you have to link them in the final application for static libs.

See here for the full discussion.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Undefined references with CodeBlocks and MinGW
« Reply #2 on: December 19, 2013, 06:21:47 pm »
Right on. I'll check that out this evening. Should I post any further questions to that thread or this one?

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Undefined references with CodeBlocks and MinGW
« Reply #3 on: December 20, 2013, 04:10:29 am »
I found this list in the linked thread:

Using MinGW I did the following setup:

Defines
GLEW_STATIC
SFML_STATIC
UNICODE

Libraries
sfml-audio-s
sfml-graphics-s
sfml-network-s
sfml-window-s
sfml-system-s
sndfile
openal32
jpeg
glew
freetype
ws2_32
gdi32
opengl32
winmm

I've added all these and the SFML libs I compiled the other other day work great now.

Thanks for pointing me in the right direction!
« Last Edit: December 20, 2013, 06:29:08 am by NoobsArePeople2 »

 

anything