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

Author Topic: how to use SFML LIbarys in Cmake ?  (Read 5968 times)

0 Members and 1 Guest are viewing this topic.

Arknode

  • Newbie
  • *
  • Posts: 1
    • View Profile
how to use SFML LIbarys in Cmake ?
« on: August 13, 2013, 05:10:08 pm »
Hello all,

iam new at cmake and i do not know really how link a libary in it. I start with the book "mastering cmake" and i think its really bad. Whatever.

I have compiled the libary from SFML by my own on Ubuntu. The libarys is located in the std-path usr/local/lib and the compiling by command line works fine.

First i found the FindSFML.cmake on the book-github dir. https://github.com/SFML/SFML-Game-Development-Book/blob/master/CMake/FindSFML.cmake  i use it with this CMakeLists.txt

Code: [Select]
cmake_minimum_required (VERSION 2.8)
project(SFML_Test)

set (TEST_SRCS main.cpp check.cpp)

find_package(SFML COMPONENTS graphics window system)
add_executable (SFML_Test ${TEST_SRCS})
target_link_libraries(SFML_Test ${SFML_LIBRARIES})

If i run cmake. it shows this

Quote
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Warning at CMakeLists.txt:6 (find_package):
  By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SFML", but
  CMake did not find one.

  Could not find a package configuration file provided by "SFML" with any of
  the following names:

    SFMLConfig.cmake
    sfml-config.cmake

  Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
  "SFML_DIR" to a directory containing one of the above files.  If "SFML"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring done
-- Generating done
-- Build files have been written to: /...

If i run make now

Quote
[ 50%] Building CXX object CMakeFiles/SFML_Test.dir/main.cpp.o
[100%] Building CXX object CMakeFiles/SFML_Test.dir/check.cpp.o
Linking CXX executable SFML_Test
CMakeFiles/SFML_Test.dir/main.cpp.o: In function `main':
main.cpp:(.text+0xf7): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text+0x115): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text+0x148): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text+0x182): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text+0x18e): undefined reference to `sf::Color::Green'
main.cpp:(.text+0x196): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text+0x1b4): undefined reference to `sf::Window::close()'
main.cpp:(.text+0x1cd): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text+0x1fa): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x217): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text+0x22e): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text+0x239): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text+0x248): undefined reference to `sf::Window::display()'
main.cpp:(.text+0x257): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text+0x282): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2b1): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x2f7): undefined reference to `sf::RenderWindow::~RenderWindow()'
CMakeFiles/SFML_Test.dir/main.cpp.o: In function `sf::CircleShape::~CircleShape()':
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x13): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x1f): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text._ZN2sf11CircleShapeD2Ev[_ZN2sf11CircleShapeD5Ev]+0x2b): undefined reference to `sf::Shape::~Shape()'
collect2: Fehler: ld gab 1 als Ende-Status zurück
make[2]: *** [SFML_Test] Fehler 1
make[1]: *** [CMakeFiles/SFML_Test.dir/all] Fehler 2
make: *** [all] Fehler 2

Maybe anyone knows how to fix this?

best regards
« Last Edit: August 13, 2013, 05:25:23 pm by Arknode »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: how to use SFML LIbarys in Cmake ?
« Reply #1 on: August 13, 2013, 05:59:45 pm »
You don't need to "master" cmake in order to compile SFML. What I suggest is that you follow Laurent's great tutorial step by step.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: how to use SFML LIbarys in Cmake ?
« Reply #2 on: August 13, 2013, 06:01:20 pm »
FindSFML.cmake must either be in the CMake module folder (/usr/share/cmake/modules ... or something), or you can add its path to the CMAKE_MODULE_PATH (or something ;D) CMake variable.
Laurent Gomila - SFML developer

Sonkun

  • Full Member
  • ***
  • Posts: 241
    • View Profile
Re: how to use SFML LIbarys in Cmake ?
« Reply #3 on: August 14, 2013, 08:39:45 am »
FindSFML.cmake must either be in the CMake module folder (/usr/share/cmake/modules ... or something), or you can add its path to the CMAKE_MODULE_PATH (or something ;D) CMake variable.
Yeah, something like that :D

Actually, it will work if you move FindSFML.cmake to /usr/share/cmake-x-y/Modules but this directory is for FindXXX.cmake scripts that comes with CMake. The actual directories are listed there: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:find_package But often, each Linux distributions define a standard place for these scripts.
Interested in using SFML with Python ? Try out its Python binding!