SFML community forums

Help => General => Topic started by: Nexus on April 27, 2011, 05:56:59 pm

Title: Static link in MinGW
Post by: Nexus 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?
Title: Static link in MinGW
Post by: Laurent 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
Title: Re: Static link in MinGW
Post by: P@u1 on April 27, 2011, 07:41:24 pm
Quote from: "Nexus"
the SFML pong example


Please tell me, where can I find it.
Title: Static link in MinGW
Post by: Laurent 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.
Title: Static link in MinGW
Post by: Nexus 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.