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

Author Topic: [CMake]Could NOT find SFML  (Read 9953 times)

0 Members and 3 Guests are viewing this topic.

Saitei

  • Newbie
  • *
  • Posts: 23
    • View Profile
[CMake]Could NOT find SFML
« on: June 23, 2016, 05:39:17 pm »
Quote
cmake_minimum_required(VERSION 2.8)
project(ECS_GameEngine)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

#aux_source_directory(. SRC_LIST)
set(SRC_LIST ${SRC_LIST} main.cpp entity.h component.cpp system.cpp channel.cpp
    gamestate.h engine.h)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_executable(${PROJECT_NAME} ${SRC_LIST})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2/cmake/Modules")
set(SFML_ROOT "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2")
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 REQUIRED system window graphics network audio)

if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()

Also I install the following libraries:
Quote
sudo apt-get install libpthread-stubs0-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libx11-dev
sudo apt-get install libxrandr-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libglew1.5-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install libsndfile1-dev
sudo apt-get install libopenal-dev
sudo apt-get install cmake
sudo apt-get install g++

Error:
Quote
/home/saitei/Projects/ECS_GameEngine/deps/SFML-2.3.2/cmake/Modules/FindSFML.cmake:358: ошибка: Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY) CMakeLists.txt:23 (find_package)


How can I fix this problem?

Saitei

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: [CMake]Could NOT find SFML
« Reply #1 on: June 23, 2016, 05:40:37 pm »
Oh! My bad, sorry!
Quote
find_package(SFML 2 COMPONENTS system window graphics network audio)


Hm... But my problem still actual:
Quote
18:56:56: Выполняются этапы для проекта ECS_GameEngine...
18:56:56: Запускается: «/usr/bin/cmake» --build . --target all
Linking CXX executable /home/saitei/Projects/ECS_GameEngine/bin/ECS_GameEngine
CMakeFiles/ECS_GameEngine.dir/main.cpp.o: In function `main':
main.cpp:(.text.startup+0x4b): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text.startup+0x64): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text.startup+0x87): undefined reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text.startup+0xae): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text.startup+0xd3): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text.startup+0xe1): undefined reference to `sf::Window::display()'
main.cpp:(.text.startup+0xf6): undefined reference to `sf::Window::close()'
main.cpp:(.text.startup+0x102): undefined reference to `sf::Window::~Window()'
main.cpp:(.text.startup+0x13d): undefined reference to `sf::Window::~Window()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/saitei/Projects/ECS_GameEngine/bin/ECS_GameEngine] Error 1
make[1]: *** [CMakeFiles/ECS_GameEngine.dir/all] Error 2
make: *** [all] Error 2
18:56:56: Процесс «/usr/bin/cmake» завершился с кодом 2.
Ошибка при сборке/установке проекта ECS_GameEngine (комплект: Desktop Qt 5.6.0 GCC 64bit)
Во время выполнения этапа «Сборка»
18:56:56: Прошло времени: 00:00.

#include <SFML/Graphics.hpp>

int main(int argc, char* argv[])
{
  sf::Window App(sf::VideoMode(800, 600), "myproject");

  while (App.isOpen())
  {
    sf::Event Event;
    while (App.pollEvent(Event))
    {
      if (Event.type == sf::Event::Closed)
        App.close();
    }
    App.display();
  }

Quote
cmake_minimum_required(VERSION 2.8)
project(ECS_GameEngine)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

set(SRC_LIST ${SRC_LIST} main.cpp entity.h component.cpp system.cpp channel.cpp
    gamestate.h engine.h)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(SFML_ROOT "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2")
set(SFML_STATIC_LIBRARIES TRUE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2/cmake/Modules")
find_package(SFML 2 COMPONENTS system window graphics network audio)

include_directories(${SFML_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
« Last Edit: June 23, 2016, 05:58:15 pm by Saitei »

Saitei

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: [CMake]Could NOT find SFML
« Reply #2 on: June 23, 2016, 10:44:06 pm »
Can anyone help me, please? :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: [CMake]Could NOT find SFML
« Reply #3 on: June 24, 2016, 08:33:10 am »
The libraries aren't getting linked, not sure why though. You could rub make with the verbose output and look at the build commands used by CMake.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SeriousITGuy

  • Full Member
  • ***
  • Posts: 123
  • Still learning...
    • View Profile
Re: [CMake]Could NOT find SFML
« Reply #4 on: June 27, 2016, 09:17:44 am »
As far as I can see, you try to link statically, so you need the static libs. Check if they are present in your SFML directory (e.g. libsfml-system-s.so) because on Linux the default SFML package does not supply the static libs (because that is not how one links on Linux). You can build them yourself from source if you really need them, that is no big hassle. But I strongly recommend using the dynamic libs on *nix OS'es and then supply them alongside your binary and set LD_LIBRARY_PATH via a start script.

Limeoats

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Limeoats
Re: [CMake]Could NOT find SFML
« Reply #5 on: June 28, 2016, 03:29:23 pm »
You shouldn't need to use COMPONENTS. I simply have this for the SFML code in my CMakeLists.txt

Quote
include(FindPkgConfig)
find_package(SFML REQUIRED system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
if(WIN32)
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} -lmingw32 -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid)
else()
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES}  )
endif()

This works on both Windows and Mac.

Of course, you need FindSFML.cmake to use this, but I assume you already are since it seems to be including fine (just the linking is the problem).