0

I do have the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(testovnik)

include_directories(include)

file(GLOB SOURCES "src/*.cpp" "include/*.hpp")
file(GLOB TESTS "tests/*.cpp")

set(EXECUTABLE_NAME "testovnik")

add_executable(${EXECUTABLE_NAME} ${SOURCES})

if(WIN32)
    set(SFML_ROOT "C:/lib/SFML")
endif()

set_target_properties(${EXECUTABLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 REQUIRED graphics window system)
if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()

When I do cmake on Windows, it works perfectly. Creates a .sln, then I can go build the whole project and it works. Now I want to do the same on Linux, necessarily linking it statically. But it doesn't work. I get the following error:

[frynio@manjaro bin]$ cmake ..
CMake Error at /usr/share/cmake-3.10/Modules/FindSFML.cmake:355 (message):
  Could NOT find SFML (missing: SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY
  SFML_SYSTEM_LIBRARY)
Call Stack (most recent call first):
  CMakeLists.txt:22 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/frynio/projects/cpp/testovnik_cpp/bin/CMakeFiles/CMakeOutput.log".

If I comment/delete the line set(SFML_STATIC_LIBRARIES TRUE) then it works. I can change it to set(SFML_STATIC TRUE), then it also works, make works too. But if I make the project, I get the executable, but still if I uninstall sfml (sudo pacman -R sfml) then I get the following error when trying to launch it:

[frynio@manjaro bin]$ ./testovnik
./testovnik: error while loading shared libraries: libsfml-graphics.so.2.4: cannot open shared object file: No such file or directory

Is there any way to build my project and give it to somebody else without them having to have sfml installed?

minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
  • Are you sure that you have static SFML libraries installed on Linux machine? – Tsyvarev Feb 05 '18 at 20:43
  • I don't. But when I copy them from the `sfml` download site (the ones with `-s`) it does pass, but it throws so many errors saying: `relocation [...] cannot be used when making a shared object` and it says I should compile with `-fPIC` (which doesn't help at all) – minecraftplayer1234 Feb 05 '18 at 20:49
  • So your problem is not linking with SFML statically, but obtaining SFML static libraries, isn't it? – Tsyvarev Feb 05 '18 at 21:43
  • I guess that's true. But still, cannot fix that – minecraftplayer1234 Feb 05 '18 at 21:46
  • 1
    "but it throws so many errors saying: `relocation [...] cannot be used when making a shared object` and it says I should compile with `-fPIC` (which doesn't help at all)" - It says that you need to have **SFML** itself to be compiled with -fPIC for being able to link with it. – Tsyvarev Feb 05 '18 at 22:29
  • "necessarily linking it statically". Why necessarily? What's wrong with linking the SMFL shared libraries provided by your Linux package manager? – Mike Kinghan Feb 06 '18 at 10:37

1 Answers1

0

Supposing you are using Archlinux (pacman ?), you can see that the sfml package only contains shared libaries...

You should consider to build from source the SFML library to get the static libraries...

ps: you can also use pacman -Ql sfml
Q: query mode
l: list files

Mizux
  • 8,222
  • 7
  • 32
  • 48