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

Author Topic: Static Linking SFML with MinGW in Eclipse  (Read 4025 times)

0 Members and 1 Guest are viewing this topic.

Bamboo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Static Linking SFML with MinGW in Eclipse
« on: November 25, 2017, 05:23:30 pm »
I'm sorry, this is probably the 10000th time someone posted about this issue and I already feel like a complete idiot about this, but I just couldn't get static linking of SFML libraries to work for me. Maybe I failed to follow the tutorials and documentations I've read about this, or maybe they were incomplete or not suitable for my case. I'd be very happy to have someone help me with this, please be patient with me  :-[

So, my OS is Windows 10 Pro 64 bit. I'd like to use the Eclipse (Eclipse Oxygen for C/C++ 64bit) IDE, because I'm familiar with it from using Java. I had already installed MinGW 6.3.0 (64 bit) for some C++ projects in Eclipse, which worked fine for me.

I downloaded SFML 2.4.2 (GCC 6.1.0 MinGW (DW2) - 32-bit) from https://www.sfml-dev.org/download/sfml/2.4.2/, and used the link to download the suiting MinGW environment (MinGW Builds 6.1.0 (32-bit)).

I figured, I could just rename my MinGW installation folder (C:\MinGW was added to the path variable and recognized by eclipse) to the version I want to use, so I changed it to the fresh 6.1.0 version that way.

This worked for me, so I think I configured Eclipse properly to work with the required MinGW 6.1.0 (32bit).
I put the SFML folder in another place, let's say {SFML_DIR}.

I set up a new project, and set the properties to the following values:
Include paths (debug/release): {SFML_DIR}\include
Library search path (debug/release): {SFML_DIR}\lib
Libraries:
sfml-graphics-d
sfml-window-d
sfml-audio-d
sfml-network-d
sfml-system-d
(debug, without the '-d' for release).

This also worked fine for me.

But the same configurations (besides changing library names accordingly and defining SFML_STATIC) for static linking failed , I get the following error message:

17:10:59 **** Incremental Build of configuration Debug for project TemplateSFMLStatic ****
Info: Configuration "Debug" uses tool-chain "MinGW GCC" that is unsupported on this system, attempting to build anyway.
Info: Internal Builder is used for build
g++ "-LC:\\Projekte\\Libraries\\C++\\SFML-2.4.2-MinGW-32\\lib" -o TemplateSFMLStatic.exe "src\\TemplateSFML.o" -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-audio-s-d -lsfml-network-s-d -lsfml-system-s-d
C:\Projekte\Libraries\C++\SFML-2.4.2-MinGW-32\lib/libsfml-graphics-s-d.a(RenderTarget.cpp.obj): In function `ZN2sf12RenderTarget5clearERKNS_5ColorE':
D:/sfml-release/_Sources/SFML/src/SFML/Graphics/RenderTarget.cpp:106: undefined reference to `glClearColor@16'
D:/sfml-release/_Sources/SFML/src/SFML/Graphics/RenderTarget.cpp:107: undefined reference to `glClear@4'
C:\Projekte\Libraries\C++\SFML-2.4.2-MinGW-32\lib/libsfml-graphics-s-d.a(RenderTarget.cpp.obj): In function `ZN2sf12RenderTarget4drawEPKNS_6VertexEjNS_13PrimitiveTypeERKNS_12RenderStatesE':
D:/sfml-release/_Sources/SFML/src/SFML/Graphics/RenderTarget.cpp:276: undefined reference to `glVertexPointer@16'
D:/sfml-release/_Sources/SFML/src/SFML/Graphics/RenderTarget.cpp:277: undefined reference to `glColorPointer@16'

.
.
.

D:/sfml-release/_Sources/SFML/src/SFML/System/Win32/SleepImpl.cpp:44: undefined reference to `_imp__timeBeginPeriod@4'
D:/sfml-release/_Sources/SFML/src/SFML/System/Win32/SleepImpl.cpp:50: undefined reference to `_imp__timeEndPeriod@4'
collect2.exe: error: ld returned 1 exit status

17:11:00 Build Finished (took 355ms)


The original error message is much longer, but it mainly consists of "undefined reference" errors, so I figured that it maybe wouldn't provide any more information. If it should be important, I can post the whole thing.


Could someone please help me understand why I get this error? Does it maybe have to do with other dependencies? I'm fine with using the dynamic linking for now, but I think I would want to use the static linking one day. But maybe, if this can't get resolved easily, it's better for me to stick to dynamic linking after all, what do you think?

Thank you in advance.

« Last Edit: November 25, 2017, 05:27:11 pm by Bamboo »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Static Linking SFML with MinGW in Eclipse
« Reply #1 on: November 25, 2017, 05:54:29 pm »
Yes, you need to link everything yourself when static linking: https://www.sfml-dev.org/tutorials/2.4/start-cb.php#creating-and-configuring-a-sfml-project
Back to C++ gamedev with SFML in May 2023

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Static Linking SFML with MinGW in Eclipse
« Reply #2 on: November 25, 2017, 06:02:08 pm »
Maybe some lines from my CMake file could help :)

        SET ( CMAKE_CXX_FLAGS  "-DSFML_STATIC -s -std=c++11" )
        SET ( CMAKE_EXE_LINKER_FLAGS  "-mwindows -static-libgcc -static-libstdc++ -static -Wl,-Bstatic -Wl,-rpath,./lib/" )
        SET ( CMAKE_LINK_LIBS sfml-audio-s sfml-graphics-s sfml-window-s sfml-system-s winmm opengl32 gdi32 freetype glew jpeg opengl32 openal32 pthread FLAC vorbisfile vorbisenc vorbis ogg sndfile )
 

Bamboo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static Linking SFML with MinGW in Eclipse
« Reply #3 on: December 08, 2017, 09:34:03 am »
Thank you! I added the necessary dependencies and now it builds and runs properly.

I encounter some strange error messages now, though. They only show in the editor, not during build. So at the moment, dynamic and static building (and running) works, but I get some errors in the static project that don't appear in the exact same code in the dynamic project, like:


sf::CircleShape shape(100.f);
shape.setPointCount(128);

"The type 'sf::CircleShape' must implement the inherited pure virtual method 'sf::Shape::getPoint' "
"Invalid arguments '
Candidates are:
void setPointCount(?)
'"


Can anyone explain? The project properties of the static and the dynamic one are exactly the same, aside from different libraries and the "SFML_STATIC" preprocessor directive.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Static Linking SFML with MinGW in Eclipse
« Reply #4 on: December 08, 2017, 09:41:53 am »
Quote
They only show in the editor, not during build
So, to be clear, there's nothing wrong except some buggy behaviour of your IDE?
Laurent Gomila - SFML developer

Bamboo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static Linking SFML with MinGW in Eclipse
« Reply #5 on: December 09, 2017, 05:51:23 pm »
I think so, but only when statically linking, which I don't really understand.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Static Linking SFML with MinGW in Eclipse
« Reply #6 on: December 09, 2017, 06:31:16 pm »
In any case, I don't think there is anything wrong on SFML side. I don't know what you expect from us.
Laurent Gomila - SFML developer

Bamboo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static Linking SFML with MinGW in Eclipse
« Reply #7 on: December 14, 2017, 09:19:38 pm »
I don't know what you expect from us.

Oh, I'm already very happy with the answers I got, thank you :) I just figured this might be the most likely place to find someone who has had a similar problem. Apart from that I think you can consider this case closed.

 

anything