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:
..\..\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:
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):
#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?