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

Author Topic: Static link in MinGW  (Read 4882 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Static link in MinGW
« on: April 27, 2011, 05:56:59 pm »
Hello,

Perhaps it's just me, but I haven't succeeded to link SFML statically on g++ with MinGW. I use the following CMake script and try to compile the SFML pong example:
Code: [Select]
cmake_minimum_required(VERSION 2.8)

project(PongExperiment)

set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 COMPONENTS system window graphics audio)
message(STATUS "Libraries [${SFML_LIBRARIES}]")

include_directories(${SFML_INCLUDE_DIR})

add_executable(PongExperiment Pong.cpp)
add_definitions(-DSFML_STATIC)

target_link_libraries(PongExperiment ${SFML_LIBRARIES})
if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
    set_target_properties(PongExperiment PROPERTIES LINK_FLAGS "-static-libgcc")
endif()

install(TARGETS PongExperiment RUNTIME DESTINATION .)

While running CMake, I get the output of the following form, so the libraries have been chosen correctly.
Code: [Select]
debug;<PATH>/libsfml-system-s-d.a;optimized;<PATH>/libsfml-system-s.a;
When I execute Make, I get loads of undefined symbols, here an example:
Code: [Select]
C:\Program Files\C++ Libraries\SFML\MinGW\lib\libsfml-window-s.a(Window.cpp.obj)
:Window.cpp:(.text+0x445): undefined reference to `sf::Err()'

The same CMake script works fine with Visual Studio 2010 as generator. Do you know what might be wrong?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Static link in MinGW
« Reply #1 on: April 27, 2011, 07:15:20 pm »
gcc is picky about the order of libraries. Try this instead:
Code: [Select]
find_package(SFML 2 COMPONENTS audio graphics window system)
And don't say "FindSFML.cmake could reorder them automatically" :D
Laurent Gomila - SFML developer

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Re: Static link in MinGW
« Reply #2 on: April 27, 2011, 07:41:24 pm »
Quote from: "Nexus"
the SFML pong example


Please tell me, where can I find it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Static link in MinGW
« Reply #3 on: April 27, 2011, 07:49:58 pm »
Quote
Please tell me, where can I find it.

examples/pong.
Next time use the search feature of your OS ;)
And don't hijack other people's threads please.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Static link in MinGW
« Reply #4 on: April 27, 2011, 07:51:26 pm »
Quote from: "Laurent"
gcc is picky about the order of libraries. Try this instead
Ah thanks, this works. I thought CMake was intelligent enough to recognize and resolve dependencies ;)

By the way, do you know how to add "-enable-auto-import" to the g++ flags? I've tried to insert it next to "-static-libgcc" in several combinations, to no avail.
Edit: Resolved, the error was still resulting from the inverted library order.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: