1

Sorry for my English, not my main language, hope everyone will understand. I'm trying to make games for the first time, five years after my first line of code. Since I want to make something organised and easy to read, I decided to use CMake to create a Visual Studio project containing various libraries for different parts of my future code, and to link each libraries with the SFML where I need it.

Unfortunately, I'm not really good at CMake. So, what should have taken a little of my time took a loooot more. I've already overcome some difficulties, but right now, I'm very blocked. Everything I try don't resolve my problem so it's really annoying.

Well, the problem now! Every libraries that I create should have been linked to the SFML one. Except, they obviously don't. That the error I got when I compile my solution (they're in french, but I think you'll get the idea):

  • core_data.lib(GameLoop.obj) : error LNK2001: symbole externe non résolu "public: virtual __thiscall sf::Window::~Window(void)" (??1Window@sf@@UAE@XZ)

  • core_data.lib(GameLoop.obj) : error LNK2019: symbole externe non résolu "public: __thiscall sf::String::String(class std::basic_string,class std::allocator > const &,class std::locale const &)" (??0String@sf@@QAE@ABV?$basic_string@DU?

  • $char_traits@D@std@@V?$allocator@D@2@@std@@ABVlocale@3@@Z) référencé dans la fonction "private: void __thiscall GameLoop::initMainWindow(void)" (?initMainWindow@GameLoop@@AAEXXZ)

  • core_data.lib(GameLoop.obj) : error LNK2019: symbole externe non résolu "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QAE@III@Z) référencé dans la fonction "private: void __thiscall GameLoop::initMainWindow(void)" (?initMainWindow@GameLoop@@AAEXXZ)

  • core_data.lib(GameLoop.obj) : error LNK2019: symbole externe non résolu "public: __thiscall sf::Window::Window(void)" (??0Window@sf@@QAE@XZ) référencé dans la fonction "public: __thiscall GameLoop::GameLoop(class std::basic_string,class std::allocator >,unsigned int,unsigned int)" (??0GameLoop@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@II@Z)

  • core_data.lib(GameLoop.obj) : error LNK2019: symbole externe non résolu "public: void __thiscall sf::Window::create(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (?create@Window@sf@@QAEXVVideoMode@2@ABVString@2@IABUContextSettings@2@@Z) référencé dans la fonction "private: void __thiscall GameLoop::initMainWindow(void)" (?initMainWindow@GameLoop@@AAEXXZ)

  • core_data.lib(GameLoop.obj) : error LNK2019: symbole externe non résolu "public: bool __thiscall sf::Window::isOpen(void)const " (?isOpen@Window@sf@@QBE_NXZ) référencé dans la fonction "public: int __thiscall GameLoop::run(void)" (?run@GameLoop@@QAEHXZ)

  • C:\Users\Fleurus\Desktop\build\sfmlBase\bin\Debug\sfmlBase.exe : fatal error LNK1120: 6 externes non résolus

Every call to a SFML function end up to a linkage error. If I'm not wrong, that's the sign of .lib that are not included. Except they seem to be included by what I did in the CMakeLists.txt. What's below is a macro that is called for every library created that use the SFML:

MACRO(Library_Configuration)

# We get the name of the current builded library with the name of the current directory
get_filename_component(LIB_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) 
# We set the complete name of the library
set(COMPLETE_LIBRARY_NAME  ${MOD_NAME}_${LIB_NAME})
# We define the path of the headers files
set(HEADER_FILES_PATH ../../../include/${MOD_NAME})
# Inclusion of headers files
file(GLOB HEADER_FILES ${HEADER_FILES_PATH}/${LIB_NAME}/*.h)
# If there is header files
if(EXISTS ${HEADER_FILES})
    set(LIBRARY_BUILT ON)
    # We take every source files of the current directory 
    file(GLOB SOURCES_FILES *.cpp)      
    # We build the library with headers and sources previously research
    add_library(${COMPLETE_LIBRARY_NAME} ${HEADER_FILES} ${SOURCES_FILES})
    # That's where seems to be the problem
    target_include_directories(${COMPLETE_LIBRARY_NAME} PUBLIC ${HEADER_FILES_PATH} ${SFML_INCLUDE_DIR} ${CMAKE_BINARY_DIR}/export) 
    target_link_libraries(${COMPLETE_LIBRARY_NAME} ${SFML_LIBRARIES})
    set_property(TARGET ${COMPLETE_LIBRARY_NAME} PROPERTY FOLDER ${MOD_NAME})

    # Fichier d'export... 
    generate_export_header(${COMPLETE_LIBRARY_NAME} EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/export/${COMPLETE_LIBRARY_NAME}_export.h)
    set (LIBRARY_BUILT_LIST )
    set (LIBRARY_BUILT_LIST ${LIBRARY_BUILT_LIST} ${COMPLETE_LIBRARY_NAME} CACHE INTERNAL "LIBRARY_BUILT_LIST")

else()
    set(LIBRARY_BUILT OFF) 
endif()
ENDMACRO()

For a better understanding, this is the architecture of my work directory:

  • app (Where the entry point of my program is)
  • include(Should be obvious)
    • core
      • physics
      • audio
      • data
      • controls
      • graphics
    • game
      • physics
      • audio
      • data
      • controls
      • graphics
  • src
    • core
      • physics
      • audio
      • data
      • controls
      • graphics
    • game
      • physics
      • audio
      • data
      • controls
      • graphics
  • CMakeLists.txt (the main one)

There it is. Hope I'm clear enough for you to help me. Thank you!

Edit : Thank you for the tag as duplicate, but the thread doesn't really help. I know what is the LNK2019 error, I don't know how to resolve this error adding something in my Cmakelist macro...

RohLeLourd
  • 11
  • 3

0 Answers0