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

Author Topic: Error building SFML test program  (Read 6100 times)

0 Members and 1 Guest are viewing this topic.

Hepple

  • Newbie
  • *
  • Posts: 5
    • View Profile
Error building SFML test program
« on: January 12, 2015, 04:53:03 am »
I am trying to set up a simple SFML test program. All it (should) do is open a window but I can't get it it run. My current system is Windows 8.1. I am using Eclipse with MinGW32 which has G++ version 4.8.1. I am building 32 bit binaries. I am using SFML 2.2.

Test Program
//#define SFML_STATIC //I have this commented out because last time I tried I was dynamically linking, but I have made sure I uncommented it when I was testing the static linking
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

int main()
{
        //OpenGL context settings
        sf::ContextSettings settings;
        settings.depthBits = 24;
        settings.stencilBits = 8;
        settings.antialiasingLevel = 2; //2x anti-aliasing

        //Create the window
        sf::Window window(sf::VideoMode(800, 600), "Hello SFML", sf::Style::Close, settings);

        bool running = true;
        while(running)
        {
                /* Render here */

                //Poll events and handle them
            sf::Event windowEvent;
            while (window.pollEvent(windowEvent))
            {
                switch (windowEvent.type)
                {

                //Exit if window closed
                case sf::Event::Closed:
                    running = false;
                    break;

                //Exit on ESC key pressed
                case sf::Event::KeyPressed:
                    if (windowEvent.key.code == sf::Keyboard::Escape)
                        running = false;
                    break;

                default:
                        break;
                }
            }
        }

    return 0;
}

So far I have tried both static and dynamic linking. I have also tried both debug and release modes and that had no effect on the outcome. I'd like to be able to do both of them (but if it's easier to solve one at a time I suppose I'd like to get dynamic linking working first.)

Dynamic Linking
For dynamic linking I linked with: sfml-system, sfml-window and included sfml-system-2.dll and sfml-window-2.dll with the executable. The program compiles but when I try to run it I get the error: "The program has stopped working". (I have also tried building a debug version with the respective -d library versions but the result is the same). There is no other information.

Static Linking
For the static linking I linked with: sfml-system-s, sfml-window-s, opengl32, winmm and gdi32.
The error I got was: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: main.o: bad reloc address 0x80 in section `.text.startup'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation


Here is the full compilation report:
Code: [Select]
16:40:28 **** Incremental Build of configuration Release for project HelloSFML ****
Info: Internal Builder is used for build
g++ "-IC:\\Libraries\\SFML\\SFML-2.2\\include" -O3 -Wall -c -fmessage-length=0 -v -o main.o "..\\main.cpp"
Using built-in specs.
COLLECT_GCC=g++
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-I' 'C:\Libraries\SFML\SFML-2.2\include' '-O3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'main.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/cc1plus.exe -quiet -v -I C:\Libraries\SFML\SFML-2.2\include -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.8.1/ ..\main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=pentiumpro -auxbase-strip main.o -O3 -Wall -version -fmessage-length=0 -o C:\Users\Francis\AppData\Local\Temp\ccUJ3f5e.s
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../include"
ignoring duplicate directory "/mingw/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/include-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.8.1/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Libraries\SFML\SFML-2.2\include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/mingw32
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include/c++/backward
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/../../../../include
 c:\mingw\bin\../lib/gcc/mingw32/4.8.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.8.1 (mingw32)
compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1ebc2a6f92fbd3aadc367a20a63fdf9f
COLLECT_GCC_OPTIONS='-I' 'C:\Libraries\SFML\SFML-2.2\include' '-O3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'main.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
 c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/as.exe -v -I C:\Libraries\SFML\SFML-2.2\include -o main.o C:\Users\Francis\AppData\Local\Temp\ccUJ3f5e.s
GNU assembler version 2.24 (mingw32) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
COLLECT_GCC_OPTIONS='-I' 'C:\Libraries\SFML\SFML-2.2\include' '-O3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'main.o' '-shared-libgcc' '-mtune=generic' '-march=pentiumpro'
g++ "-LC:\\Libraries\\SFML\\SFML-2.2\\lib" -o HelloSFML.exe main.o -lsfml-system-s -lsfml-window-s -lopengl32 -lwinmm -lgdi32
C:\Libraries\SFML\SFML-2.2\lib/libsfml-system-s.a(String.cpp.obj):String.cpp:(.text+0xb66): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
C:\Libraries\SFML\SFML-2.2\lib/libsfml-system-s.a(String.cpp.obj):String.cpp:(.text+0xebc): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
C:\Libraries\SFML\SFML-2.2\lib/libsfml-system-s.a(String.cpp.obj):String.cpp:(.text+0x27c6): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
C:\Libraries\SFML\SFML-2.2\lib/libsfml-system-s.a(String.cpp.obj):String.cpp:(.text+0x2bd0): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Libraries\SFML\SFML-2.2\lib/libsfml-system-s.a(String.cpp.obj): bad reloc address 0x13 in section `.text.unlikely'
collect2.exe: error: ld returned 1 exit status

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Error building SFML test program
« Reply #1 on: January 12, 2015, 10:55:52 am »
Maybe the precompiled binaries of SFML doesn't match your compiler because the SFML binaries are compiled with the TDM compilers, could you try to compile SFML by yourself?
http://www.sfml-dev.org/tutorials/2.2/compile-with-cmake.php


AlexAUT
« Last Edit: January 12, 2015, 10:58:00 am by AlexAUT »

Hepple

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Error building SFML test program
« Reply #2 on: January 12, 2015, 08:26:57 pm »
Thanks Alex,

I've just tried building SFML from source. That seemed to be successful (so far I've only build the release versions for both static and dynamic linking).

Now I get the same error when I try to build my program - regardless of the linking type:

Code: [Select]
main.o:main.cpp:(.text.startup+0x70): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
main.o:main.cpp:(.text.startup+0x98): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
main.o:main.cpp:(.text.startup+0x4a): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.o:main.cpp:(.text.startup+0x7d): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
main.o:main.cpp:(.text.startup+0x82): undefined reference to `_imp___ZN2sf5Color5GreenE'
main.o:main.cpp:(.text.startup+0x94): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
main.o:main.cpp:(.text.startup+0x9a): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
main.o:main.cpp:(.text.startup+0xa9): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
main.o:main.cpp:(.text.startup+0xf9): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
main.o:main.cpp:(.text.startup+0x10b): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
main.o:main.cpp:(.text.startup+0x110): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
main.o:main.cpp:(.text.startup+0x12c): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
main.o:main.cpp:(.text.startup+0x13b): undefined reference to `_imp___ZN2sf6Window7displayEv'
main.o:main.cpp:(.text.startup+0x14c): undefined reference to `_imp___ZN2sf6Window5closeEv'
main.o:main.cpp:(.text.startup+0x156): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
main.o:main.cpp:(.text.startup+0x174): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
main.o:main.cpp:(.text.startup+0x180): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
main.o:main.cpp:(.text.startup+0x1bf): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
main.o:main.cpp:(.text.startup+0x1cd): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
main.o:main.cpp:(.text.startup+0x1ed): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: main.o: bad reloc address 0x20 in section `.eh_frame'

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Error building SFML test program
« Reply #3 on: January 12, 2015, 08:30:43 pm »
What you've got there is a linker error (failure to find a type/function you refer to), not a compiler error.
So, your program is syntactically valid, you are just not linking all required libraries (or linking them in the wrong order - yes, that matters; search the forum/internet).
« Last Edit: January 12, 2015, 08:32:46 pm by Jesper Juhl »

Hepple

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Error building SFML test program
« Reply #4 on: January 12, 2015, 10:13:09 pm »
Yes, I know it's a link error, I just don't know how to solve it. I've included all the libraries and included them in the right order and then changed that order in case Eclipse was doing something I wasn't aware of but I still can't get it to work. I've checked all the basics and been through google and now I need some feedback on what to try next.

Hepple

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Error building SFML test program
« Reply #5 on: January 13, 2015, 01:10:14 am »
Ok, I've managed to get my program to compile and link with both the static and dynamic versions, however both now crash when I run it with the error: "The program has stopped working". This is using the libraries I have built.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Error building SFML test program
« Reply #6 on: January 13, 2015, 09:28:51 am »
Are you sure that you are using the right libs? Because in my experience this error occurs when you use SFML-libs compiled with a different compiler.

Maybe your forgot to replace the *.dll files?


AlexAUT

Hepple

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Error building SFML test program
« Reply #7 on: January 13, 2015, 09:49:16 am »
Yes, that's been my experience with similar DLL problems.

It looks like it was linking to the wrong libraries but only because whenever I clicked run in Eclipse it build the debug version and tried to run that. I had to manually run the release version that I had told Eclipse to build first and that runs fine. I'm guessing there's some setting in Eclipse somewhere that I will need to change in the long run.

Anyway I have it working now, thanks for the help.

 

anything