SFML community forums

Help => General => Topic started by: naraku9333 on September 14, 2013, 07:38:31 pm

Title: SFML and cmake
Post by: naraku9333 on September 14, 2013, 07:38:31 pm
Hello, I am re-writing a CMakeLists.txt file for a project to use FindSFML.cmake and am having problems. The project builds fine but fails linking when static build is selected. I know it isn't a problem with the libs, I've linked to them without issue with the old CMakeLists.txt.

I would really appreciate if someone could point out what I am doing wrong or give me some suggestions. Here is my current attempt.
# ChessPlusPlus
#
# Configuration options:
# -DCMAKE_BUILD_TYPE=Release|Debug
# -DSTATIC_BUILD=1|0

cmake_minimum_required (VERSION 2.8)

project (CHESSPP)

if(WIN32)
    set(SFML_ROOT "" CACHE PATH "Path to SFML root directory")
    option(STATIC_BUILD OFF "Link statically")    
endif()

if(NOT JSONLIB)
    set(JSONLIB ${CHESSPP_SOURCE_DIR}/lib/json-parser)
endif()
if(NOT BOOSTLIB)
    set(BOOSTLIB ${CHESSPP_SOURCE_DIR}/lib/boost)
endif()

include_directories (${JSONLIB})
include_directories (${BOOSTLIB})

file(GLOB_RECURSE CHESSPP_SOURCES "src/*.cpp")
file(GLOB_RECURSE CHESSPP_HEADERS "src/*.hpp")
list(APPEND CHESSPP_SOURCES "lib/json-parser/json.c")

set (CHESSPP_INCLUDE_DIRS "")
foreach (_headerFile ${CHESSPP_HEADERS})
    get_filename_component(_dir ${_headerFile} PATH)
    list (APPEND CHESSPP_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES CHESSPP_INCLUDE_DIRS)
include_directories(${CHESSPP_INCLUDE_DIRS})

list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
 
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
if(STATIC_BUILD)
        set(SFML_STATIC_LIBRARIES TRUE)
endif()
find_package(SFML 2 REQUIRED system window graphics network audio)
include_directories (${SFML_INCLUDE_DIR})
link_directories(${SFML_ROOT}/lib)
add_executable (chesspp ${CHESSPP_SOURCES})
target_link_libraries(chesspp ${SFML_LIBRARIES} boost_system boost_filesystem)
 
Title: Re: SFML and cmake
Post by: Laurent on September 14, 2013, 08:24:21 pm
Please provide the error message. And your OS, version of SFML, etc.

But, if you're on Linux or OS X, your problem is most likely that you're not linking to the dependencies of SFML (you have to do that when you link SFML statically, except on Windows).
Title: Re: SFML and cmake
Post by: naraku9333 on September 14, 2013, 11:01:45 pm
Sorry for not specifying, this is on Windows 7 using Nuwen's MinGW distro ( nuwen.net/mingw.html ).

Here are thelink errors
Linking CXX executable chesspp.exe
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x13d): undefin
ed reference to `sf::Clock::Clock()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x144): undefin
ed reference to `sf::Time::Zero'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x471): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x55b): undefin
ed reference to `sf::Time::Zero'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x589): undefin
ed reference to `sf::seconds(float)'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x5f1): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x6f4): undefin
ed reference to `sf::Clock::restart()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x754): undefin
ed reference to `sf::Clock::Clock()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x75b): undefin
ed reference to `sf::Time::Zero'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x7ce): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x8e1): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x9c4): undefin
ed reference to `sf::Clock::Clock()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0x9d6): undefin
ed reference to `sf::Time::Zero'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xab2): undefin
ed reference to `sf::Time::Zero'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xab7): undefin
ed reference to `sf::operator!=(sf::Time, sf::Time)'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xac7): undefin
ed reference to `sf::Clock::getElapsedTime() const'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xad3): undefin
ed reference to `sf::operator-(sf::Time, sf::Time)'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xadb): undefin
ed reference to `sf::sleep(sf::Time)'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xae3): undefin
ed reference to `sf::Clock::restart()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xaf1): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xc34): undefin
ed reference to `sf::Clock::restart()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xd60): undefin
ed reference to `sf::err()'
C:/Program Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj):Window.cpp:(.text+0xe71): undefin
ed reference to `sf::err()'
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Progr
am Files (x86)/SFML/lib/libsfml-window-s.a(Window.cpp.obj): bad reloc address 0x24 in section `.xdat
a'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [chesspp.exe] Error 1
make[1]: *** [CMakeFiles/chesspp.dir/all] Error 2
make: *** [all] Error 2

C:\Users\Sean\Documents\ChessPlusPlus\build>
Title: Re: SFML and cmake
Post by: Laurent on September 14, 2013, 11:14:09 pm
Did you define SFML_STATIC?