Building SFML for Code::Blocks

Pages: 12
Disch has posted a wonderful explanation on how to set up SFML here: http://cplusplus.com/forum/beginner/95295/

Thing is, it's for Microsoft Visual Studio... I don't want to switch to another IDE from Code::Blocks (because it's really good), but I don't fully understand how should I adjust all of the steps, I think I managed to set it up right with CMake, but when I tried to build SFML.cbp I ran into trouble.
First in the guide it says to build it in both Debug and Release configurations. That's not what I get in Code::Blocks - I get many options, one of them is "all" so I assume I should choose that, but when I tried to build it, Code::Blocks failed and returned this:

g++.exe: error: unrecognized command line option '-static-libstdc++'
mingw32-make.exe[2]: *** [examples/ftp/ftp.exe] Error 1
mingw32-make.exe[1]: *** [examples/ftp/CMakeFiles/ftp.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
mingw32-make.exe[2]: Leaving directory `C:/SFML 2.0/projects'
mingw32-make.exe[1]: Leaving directory `C:/SFML 2.0/projects'
Process terminated with status 2 (7 minutes, 32 seconds)
0 errors, 0 warnings (7 minutes, 32 seconds)


I just pasted some of the last line of output here (because I think that's where the problem is).

Also as far as I know the universal header ("sfml.h") he wrote will only work on VS.
How can I make one for Code::Blocks?

EDIT: I deleted everything and started all over again and in CMake I added the directory of the Code::Blocks executable. Then the build worked, but returned 98 warnings (about how all includes were missing)
Last edited on
No? Nobody knows?
I mean, has nobody tried compiling SFML 2.0 with Code::Blocks?
I've read the tutorial by Disch and the one on SFML website, but they're both for VS.

Okay I'd like to know everything step by step, so I'll begin with what I know:

Step 1
Download SFML 2.0 and extract it, where you'd like your SFML installation to be.
(You can rename the first folder to whatever you like, but you can't change the other ones)

Step 2
Install CMake and Doxygen.

Step 3
Run CMake and select your SFML folder for the source, then choose where to build the binaries.

Step 4
Click configure and select Code::Blocks - MinGW makefiles.

That's as much as I know (well I'm sure of what to do until this part)
If I messed up somewhere, please tell me.

Then I get these options:

BUILD_SHARED_LIBS                                 Unchecked

CMAKE_BUILD_TYPE                                   Release

CMAKE_CODEBLOCKS_EXECUTABLE          CMAKE_CODEBLOCKS_EXECUTABLE-NOTFOUND

CMAKE_GNUtoMs                                       Unchecked

CMAKE_INSTALL_PREFIX                           C:/Program Files/SFML

DOXYGEN_HHC_PROGRAM                     DOXYGEN_HHC_PROGRAM-NOTFOUND

GLEW_INCLUDE_PATH                              C:/SFML 2.0/extlibs/headers

GLEW_LIBRARY                           C:/SFML 2.0/extlibs/libs-mingw/x86/libglew.a

SFML_BUILD_DOC                                      Checked

SFML_BUILD_EXAMPLES                                 Unchecked

SFML_USE_STATIC_STD_LIBS                            Checked


SFML is here: C:/SFML 2.0
Last edited on
g++.exe: error: unrecognized command line option '-static-libstdc++'

Your compiler might be to old for this option, either update mingw or change the option to something like -static-libgcc
I don't believe that my compiler is old, I'm using TDM MinGW 4.7.1 which I downloaded from their site and set it up for myself, but I'll try changing the option (I didn't enable it myself, it was enabled by default (by CMake I think) )

EDIT: Actually I don't have these options (I didn't check them before) like in a normal project. Here since you're using a custom makefile the options are different and -static-libstdc++ isn't mentioned anywhere.
However I know that this option is enabled, because I checked the box SFML_USE_STATIC_STD_LIBS

EDIT 2: The build doesn't fail anymore, but returns 98 warnings. First it says that some includes are missing (e.g. it goes to this line #include <SFML/System/Vector2.inl> and says that the file is missing)
I assume it says that all *.inl files are missing.
Then there are lots of warnings that say "no uniquely matching class member found for" and the rest are about warnings about functions that are not documented (not much of a problem I guess)

Maybe I need to set a different path for CMAKE_INSTALL_PREFIX ?
And maybe I should set the path to codeblocks.exe for CMAKE_CODEBLOCKS_EXECUTABLE ?
And maybe I should set the path to doxygen.exe for DOXYGEN_HHC_PROGRAM ?
(Originally I just left them as defaults)
Last edited on
Code blocks comes with a compiler, are you sure you're actually using TDM?
Yeah I'm pretty sure ( as far as I know :D )
I first installed Code::Blocks with the compiler attached, then I deleted it and installed Code::Blocks and the compiler separately. Maybe I should reinstall them as a bundle again?
Maybe you should try moving your executables and source and builds into paths that do not contain whitespaces. I remember on Windows that g++ woudn't correctly load the debugger if the executable/source were in a folder that had a whitespace somewhere in the path.

Also

Vidminas wrote:
CMAKE_CODEBLOCKS_EXECUTABLE CMAKE_CODEBLOCKS_EXECUTABLE-NOTFOUND


Locate it, it's probably somewhere in C:\Program Files\CodeBlocks\

Logically, CMake would need the C::B executable to know how to build a project for C::B that you can compile into a library.
The SFML website was updated quite a lot.
I downloaded their new build of v2.0, but CMake couldn't configure it.

I then got the pre-compiled binaries, which work with Code::Blocks, but I have to copy every .dll according to the libraries I use into the same directory as the executable. The tutorial doesn't mention that.

Has anybody else tried to build SFML v2.0 recently?

EDIT: Build works with CMake after a reboot.

EDIT 2: Oh God no, not again! Same error in Code::Blocks when compiling:
Linking CXX executable ftp.exe
cd /d C:\SFML-2.0\projects\examples\ftp && "C:\Program Files\CMake 2.8\bin\cmake.exe" -E cmake_link_script CMakeFiles\ftp.dir\link.txt --verbose=1
"C:\Program Files\CMake 2.8\bin\cmake.exe" -E remove -f CMakeFiles\ftp.dir/objects.a
g++.exe: error: unrecognized command line option '-static-libstdc++'
mingw32-make.exe[2]: *** [examples/ftp/ftp.exe] Error 1
mingw32-make.exe[1]: *** [examples/ftp/CMakeFiles/ftp.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
C:\MinGW-4.7.1\bin\ar.exe cr CMakeFiles\ftp.dir/objects.a @CMakeFiles\ftp.dir\objects1.rsp
C:\MinGW-4.7.1\bin\g++.exe  -O3 -DNDEBUG    -static-libgcc -static-libstdc++ -Wl,--whole-archive CMakeFiles\ftp.dir/objects.a -Wl,--no-whole-archive  -o ftp.exe -Wl,--out-implib,libftp.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ..\..\lib\libsfml-network-s.a ..\..\lib\libsfml-system-s.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
mingw32-make.exe[2]: Leaving directory `C:/SFML-2.0/projects'
mingw32-make.exe[1]: Leaving directory `C:/SFML-2.0/projects'
Process terminated with status 2 (4 minutes, 26 seconds)
0 errors, 0 warnings (4 minutes, 26 seconds)


EDIT 3: I don't get this error when compiling with SHARED_LIBS, instead I get the 98 warnings.
Last edited on
Chriscpp - I've read that many times now.
In the previous post I wrote that SFML works for me with pre-compiled libraries, I just want to compile it myself.

Vidminas wrote:
g++.exe: error: unrecognized command line option '-static-libstdc++'
naraku9333 wrote:
Your compiler might be to old for this option, either update mingw or change the option to something like -static-libgcc

I couldn't find where the option was stated, therefore I couldn't change it.

In the tutorial it says that you don't have to compile with an IDE, so I tried building just MinGW makefiles and building them.
C:\Documents and Settings\Vidminas> cd C:\SFML-2.0\projects

C:\SFML-2.0\projects>mingw32-make Makefile

Nothing happens...
Last edited on
You need to use cmake to generate a makefile first, something like
cmake -G"Unix Makefile"
then
mingw32-make
Last edited on
if you're using wnidows, you must be having no problem at all. just download the right package for your compiler, add the lib and include directories of SFML to the search directory list of code blocks, link to the libraries you will need and in the right order, just follow the link provided by chriscpp like a tut. i followed, and it was too simple

the library is pre-compiled for mingw i think, because i did not need to buid it as i did with the wxWidgets 2.9.4 library, latest(alpha/beta) release.

Aceix.
Chriscpp - I've read that many times now.

And yet you wrote:
I then got the pre-compiled binaries, which work with Code::Blocks, but I have to copy every .dll according to the libraries I use into the same directory as the executable. The tutorial doesn't mention that.

While the link provided states:
Compile it, and if you linked to the dynamic version of SFML, don't forget to copy the SFML DLLs (they are in <sfml-install-path/bin>) to the directory where your compiled executable is.

which makes me wonder if you are paying as much attention to what you read as you say you are.
@cire I'm very sorry for being so unattentive. I did see that in the tutorial, the thing I failed to understand is that with the pre-compiled SFML binaries I was linking to the dynamic and not the static libraries. I just got mixed up... (note to self "Think twice before posting")

@Aceix Thank you for this info, but I'm already past this stage
Vidminas wrote:
In the previous post I wrote that SFML works for me with pre-compiled libraries, I just want to compile it myself.


@naraku9333 Yes, I know how to build the makefiles with CMake. I've built SFML makefiles with the CMake GUI, I just don't know how to correctly invoke mingw32-make to use the makefiles to actually compile SFML.

Summary of things that happened:
Using my 7 year old laptop which has Ubuntu 12.04 as the host OS and Windows XP as the guest OS (I just want to do this on Windows, without bothering with Linux) I tried to compile SFML from source, because pre-compiled binaries didn't work, building SFML with SHARED_LIBS returns 98 warnings about missing includes. Building SFML with STATIC_STD_LIBS returns 1 error.

Then the website was updated.

Using another PC which has Windows XP as the host OS. The pre-compiled libraries work, I still want to compile it myself, though.

Building with CMake for Code::Blocks MinGW makefiles brings up the exactly same things that happened before.
I noticed that the tutorial says:
To create makefiles usable with MinGW (gcc), select "MinGW makefiles". It is generally easier to generate makefiles rather than IDE projects: you can then compile with a single command, or even gather multiple compilations in a single script. Since you will only compile, not edit source files, IDE projects are generally useless.

Until then I was creating Code::Blocks projects, so this means I should create MinGW makefiles.
Vidminas wrote:
In the tutorial it says that you don't have to compile with an IDE, so I tried building just MinGW makefiles.


This is the screen of CMD:
Vidminas wrote:

C:\Documents and Settings\Vidminas> cd C:\SFML-2.0\projects

C:\SFML-2.0\projects>mingw32-make Makefile


Vidminas wrote:
Nothing happens...
(mingw32-make doesn't execute)

So my question now is - how should I call mingw32-make?

Extra details:
The source is in C:\SFML-2.0
CMake build is in C:\SFML-2.0\projects
There are no spaces in the paths.
I want to build SFML with STATIC_STD_LIBS and not SHARED_LIBS.
C:\SFML-2.0\projects>mingw32-make Makefile
This is wrong, it should be
C:\SFML-2.0\projects>mingw32-make
assuming the projects directory is where cmake generated the makefile.
Thank you naraku9333, it worked. (mostly)
I now realise you were trying to tell me the same thing before, sorry for misunderstanding.
naraku9333 wrote:
You need to use cmake to generate a makefile first, something like
cmake -G"Unix Makefile"
then
mingw32-make


The problem (again) is the same as with using an IDE. At about 85% completion I get
g++.exe: error: unrecognized command line option '-static-libstdc++'
.
As from the start:
naraku9333 wrote:
Your compiler might be to old for this option, either update mingw or change the option to something like -static-libgcc
Vidminas wrote:
I couldn't find where the option was stated, therefore I couldn't change it.
I tried looking in the makefile and CMakeCache.txt

This is using TDM MinGW 4.7.1 as CMake cannot detect MinGW 4.8.0 from the Nuwen distro.

EDIT:
Found it in C:\SFML-2.0\cmake\Macros.cmake
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
    if(WINDOWS AND COMPILER_GCC AND SFML_USE_STATIC_STD_LIBS)
        if(NOT GCC_VERSION VERSION_LESS "4")
            set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
        endif()
    endif()

Apparently just replacing "-static-libgcc -static-libstdc++" with "static-libgcc" in notepad and then saving the file isn't good enough.

CMake complains when configuring SFML
CMake Error: Error in cmake code at
C:/SFML-2.0/cmake/Macros.cmake:1:
Parse error.  Expected a command name, got unquoted argument with text "ļ»æ".
CMake Error at src/SFML/CMakeLists.txt:3 (include):
  include could not find load file:

    C:/SFML-2.0/cmake/Macros.cmake


CMake Error at src/SFML/System/CMakeLists.txt:80 (sfml_add_library):
  Unknown CMake command "sfml_add_library".
NOTE: "static-libgcc" is with quotes.
Last edited on
To use the nuwen distro, re-run cmake select Unix Makefiles and specify native compiler then set path to c and c++ compilers (C:/MinGW/bin/gcc.exe|g++.exe for me) then after it generates run make instead of mingw32-make.
When configuring Unix makefiles
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/SFML-2.0/projects/CMakeFiles/2.8.10.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file:C:/SFML-2.0/projects/CMakeFiles/2.8.10.2/CMakeCXXCompiler.cmake
Configuring incomplete, errors occurred!


However, configuring MinGW makefiles work with Nuwen's 4.8.0 if you specify the paths to gcc.exe and g++.exe

When running mingw32-make:

[ 14%] Building CXX object src/SFML/System/CMakeFiles/sfml-system.dir/Win32/Thre
adImpl.cpp.obj
C:\DOCUME~1\Vidminas\LOCALS~1\Temp\ccouhLAq.s: Assembler messages:
C:\DOCUME~1\Vidminas\LOCALS~1\Temp\ccouhLAq.s:143: Error: expecting string instr
uction after `rep'
C:\DOCUME~1\Vidminas\LOCALS~1\Temp\ccouhLAq.s:180: Error: expecting string instr
uction after `rep'
C:\DOCUME~1\Vidminas\LOCALS~1\Temp\ccouhLAq.s:204: Error: expecting string instr
uction after `rep'
mingw32-make[2]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/Win32/ThreadImp
l.cpp.obj] Error 1
mingw32-make[1]: *** [src/SFML/System/CMakeFiles/sfml-system.dir/all] Error 2
mingw32-make: *** [all] Error 2
Last edited on
I said use make instead of mingw32-make
I know, but I couldn't configure Unix makefiles with CMake and I need to do that first, before compiling with make.
I posted the errors that I got from CMake above:
Vidminas wrote:
When configuring Unix makefiles

I used mingw32-make with MinGW makefiles. (while specifying the paths to gcc.exe and g++.exe)

Sorry, if I'm really annoying you. Honestly, I am sorry...
Last edited on
Pages: 12