SFML community forums
Help => General => Topic started 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:
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.
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:
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?
-
gcc is picky about the order of libraries. Try this instead:
find_package(SFML 2 COMPONENTS audio graphics window system)
And don't say "FindSFML.cmake could reorder them automatically" :D
-
the SFML pong example
Please tell me, where can I find it.
-
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.
-
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.