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

Author Topic: SFML & cmake error  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

genfy

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML & cmake error
« on: May 22, 2018, 09:31:42 pm »
I can run cmake just fine but when I go to make the project I get this error:
CMakeFiles/RogueLike.dir/src/Main.cpp.o: In function `main':
Main.cpp:(.text+0x75): undefined reference to `sf::String::String(char const*, std::locale const&)'  
Main.cpp:(.text+0x93): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'  
Main.cpp:(.text+0xc6): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'  
Main.cpp:(.text+0xf3): undefined reference to `sf::Window::isOpen() const'      
Main.cpp:(.text+0x110): undefined reference to `sf::Window::pollEvent(sf::Event&)'  
Main.cpp:(.text+0x12d): undefined reference to `sf::Window::close()'    
Main.cpp:(.text+0x13e): undefined reference to `sf::RenderWindow::~RenderWindow()'
Main.cpp:(.text+0x17a): undefined reference to `sf::RenderWindow::~RenderWindow()'  
Main.cpp:(.text+0x1ab): undefined reference to `sf::RenderWindow::~RenderWindow()'

This is my cmake document:
# TODO add non-linux OS compatibility
# Setup
cmake_minimum_required(VERSION 3.0)
project(RogueLike)

set(CMAKE_MODULE_PATH /usr/share/SFML/cmake/Modules)

# Libraries
# set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 COMPONENTS audio graphics window system)
if(SFML_FOUND)
        include_directories(${SFML_INCLUDE_DIR})
endif()

# Source
set(src
        src/Main.cpp
)

# Generate executable
add_executable(RogueLike ${src})

And finally my code:
#include<SFML/Graphics.hpp>

int main() {
        sf::RenderWindow window(sf::VideoMode(1280, 720), "Hello, world!");

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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML & cmake error
« Reply #1 on: May 22, 2018, 11:15:32 pm »
You're not calling target_link_libraries.

Also if you're using SFML 2.5.0 you don't need set(CMAKE_MODULE_PATH) or include_directories anymore. See also the SFMLConfig.cmake.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/