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

Author Topic: undefined reference to ...  (Read 3050 times)

0 Members and 1 Guest are viewing this topic.

wrona

  • Newbie
  • *
  • Posts: 1
    • View Profile
undefined reference to ...
« on: May 22, 2018, 11:39:14 am »
Hello,
OS: Debian testing
SFML: 2.5.0+dfsg-2
Standard install way: sudo aptitude install libsfml-dev

I have a problem with my project after updating the SFML from 2.4.2 to 2.5.0 version .When I tried to compile it i get an error message::
[ 50%] Linking CXX executable LittleHero
CMakeFiles/LittleHero.dir/main.cpp.o: In function `main':
/home/wrona/Code/C++/RPG/LittleHero/main.cpp:9: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/wrona/Code/C++/RPG/LittleHero/main.cpp:9: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/wrona/Code/C++/RPG/LittleHero/main.cpp:9: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/wrona/Code/C++/RPG/LittleHero/main.cpp:9: undefined reference to `sf::RenderWindow::~RenderWindow()'

It's only simple skeleton of project:
Code: [Select]
cmake_minimum_required(VERSION 3.10)
project(LittleHero)

set(CMAKE_CXX_STANDARD 11)

add_executable(LittleHero main.cpp)

set(CMAKE_MODULE_PATH "/usr/share/SFML/cmake/Modules/" ${CMAKE_MODULE_PATH})
find_package(SFML 2.5 REQUIRED graphics window system)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(LittleHero ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()


Code: [Select]
#include <iostream>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>

using namespace std;

int main() {

    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
    window.close();
    return 0;

}
« Last Edit: May 22, 2018, 12:22:04 pm by wrona »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: undefined reference to ...
« Reply #1 on: May 22, 2018, 12:35:16 pm »
You can remove the SET CMAKE_MODULE_PATH, remove the SFML ${} variables and remove the include directory directive.
Insteadyou need to list the librariesto link yourself, but you only need to specify the top dependencies (e.g. only sfml-graphics and no need for sfml-system).

See this file for a better overview: https://github.com/SFML/SFML/blob/master/cmake/SFMLConfig.cmake.in
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/