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

Author Topic: CMakeLists.txt  (Read 2229 times)

0 Members and 1 Guest are viewing this topic.

adomas

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Adomas Homepage
CMakeLists.txt
« on: February 28, 2013, 07:19:36 pm »
Hello,
How do I configure my project to link SFML correctly via CMake? I'm using QT Creator on Linux. I get these errors:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/adomas/SFMLTest-build
make[2]: Warning: File `CMakeFiles/SFMLTest.dir/flags.make' has modification time 6238 s in the future
Scanning dependencies of target SFMLTest
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[2]: Warning: File `CMakeFiles/SFMLTest.dir/flags.make' has modification time 6238 s in the future
[100%] Building CXX object CMakeFiles/SFMLTest.dir/main.cpp.o
Linking CXX executable SFMLTest
CMakeFiles/SFMLTest.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x6b): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text+0x92): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, std::string const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text+0xc6): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text+0xd2): undefined reference to `sf::Color::Green'
main.cpp:(.text+0xda): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text+0xf5): undefined reference to `sf::Window::close()'
main.cpp:(.text+0x10b): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text+0x130): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text+0x14a): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text+0x161): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text+0x16c): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text+0x17b): undefined reference to `sf::Window::display()'
main.cpp:(.text+0x18a): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text+0x1b5): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x1e1): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text+0x224): undefined reference to `sf::RenderWindow::~RenderWindow()'
CMakeFiles/SFMLTest.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: error: ld returned 1 exit status
make[2]: *** [SFMLTest] Error 1
make[1]: *** [CMakeFiles/SFMLTest.dir/all] Error 2
make: *** [all] Error 2
20:10:59: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project SFMLTest (kit: Desktop)
When executing step 'Make'

When I compile via terminal like this:g++ main.cpp -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

Everything is OK. What do I need to write to CMakeLists.txt to get linked with SFML 2?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMakeLists.txt
« Reply #1 on: February 28, 2013, 08:00:26 pm »
find_package(SFML 2 COMPONENTS graphics window system REQUIRED)

include_directories(${SFML_INCLUDE_DIR})

add_executable(name ...)

target_link_libraries(name ${SFML_LIBRARIES})

I wrote it from scratch, you may have to adjust the syntax or variable names.
Laurent Gomila - SFML developer