Linking, error LNK2019: unresolved external symbol

Started by EngineerBread, 01 May 2024, 19:53:09

EngineerBread

Hello everyone, I hope you are doing well.
I recently downloaded the TGUI library and tried to link it statically to my project, but when I try to compile it, I'm getting the following linking errors:

tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::WindowBase::isOpen(void)const " (?isOpen@WindowBase@sf@@QEBA_NXZ) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::mainLoop(class tgui::Color)" (?mainLoop@BackendGuiSFML@tgui@@UEAAXVColor@2@@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2001: unresolved external symbol "public: bool __cdecl sf::WindowBase::isOpen(void)const " (?isOpen@WindowBase@sf@@QEBA_NXZ)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::WindowBase::pollEvent(class sf::Event &)" (?pollEvent@WindowBase@sf@@QEAA_NAEAVEvent@2@@Z) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::mainLoop(class tgui::Color)" (?mainLoop@BackendGuiSFML@tgui@@UEAAXVColor@2@@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2001: unresolved external symbol "public: bool __cdecl sf::WindowBase::pollEvent(class sf::Event &)" (?pollEvent@WindowBase@sf@@QEAA_NAEAVEvent@2@@Z)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: class sf::Vector2<unsigned int> __cdecl sf::WindowBase::getSize(void)const " (?getSize@WindowBase@sf@@QEBA?AV?$Vector2@I@2@XZ) referenced in function "protected: virtual void __cdecl tgui::BackendGuiSFML::updateContainerSize(void)" (?updateContainerSize@BackendGuiSFML@tgui@@MEAAXXZ)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: void __cdecl sf::WindowBase::setMouseCursor(class sf::Cursor const &)" (?setMouseCursor@WindowBase@sf@@QEAAXAEBVCursor@2@@Z) referenced in function "public: virtual void __cdecl tgui::BackendSFML::detatchGui(class tgui::BackendGui *)" (?detatchGui@BackendSFML@tgui@@UEAAXPEAVBackendGui@2@@Z)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: struct HWND__ * __cdecl sf::WindowBase::getSystemHandle(void)const " (?getSystemHandle@WindowBase@sf@@QEBAPEAUHWND__@@XZ) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::updateTextCursorPosition(class tgui::Rect<float>,class tgui::Vector2<float>)" (?updateTextCursorPosition@BackendGuiSFML@tgui@@UEAAXV?$Rect@M@2@V?$Vector2@M@2@@Z)
tgui-s-d.lib(BackendFontSFML.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::Font::hasGlyph(unsigned int)const " (?hasGlyph@Font@sf@@QEBA_NI@Z) referenced in function "public: virtual bool __cdecl tgui::BackendFontSFML::hasGlyph(char32_t)const " (?hasGlyph@BackendFontSFML@tgui@@UEBA_N_U@Z)
tgui-s-d.lib(BackendFontSFML.obj) : error LNK2019: unresolved external symbol "public: float __cdecl sf::Font::getKerning(unsigned int,unsigned int,unsigned int,bool)const " (?getKerning@Font@sf@@QEBAMIII_N@Z) referenced in function "public: virtual float __cdecl tgui::BackendFontSFML::getKerning(char32_t,char32_t,unsigned int,bool)" (?getKerning@BackendFontSFML@tgui@@UEAAM_U0I_N@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2019: unresolved external symbol "public: void __cdecl sf::WindowBase::setIcon(unsigned int,unsigned int,unsigned char const *)" (?setIcon@WindowBase@sf@@QEAAXIIPEBE@Z) referenced in function "public: virtual void __cdecl tgui::BackendWindowSFML::setIcon(class tgui::String const &)" (?setIcon@BackendWindowSFML@tgui@@UEAAXAEBVString@2@@Z)

This is my cmake file:

add_library("BreadEngineCore" STATIC
  "BreadEngineCore/src/BreadEngine.h"
      "BreadEngineCore/src/Core/Application/application.cpp"
      "BreadEngineCore/src/Core/Application/application.h"
      "BreadEngineCore/src/Core/Application/entrypoint.h"
      "BreadEngineCore/src/Core/Application/sharedcontext.h"
      "BreadEngineCore/src/Core/AssetManager/assetmanager.cpp"
      "BreadEngineCore/src/Core/AssetManager/assetmanager.h"
      "BreadEngineCore/src/Core/Audio/audiohandler.cpp"
      "BreadEngineCore/src/Core/Audio/audiohandler.h"
      "BreadEngineCore/src/Core/Containers/typelist.h"
        "BreadEngineCore/src/Core/ECS/Base/Types.h"
        "BreadEngineCore/src/Core/ECS/Base/classiccomponents.h"
        "BreadEngineCore/src/Core/ECS/Base/ecs.cpp"
        "BreadEngineCore/src/Core/ECS/Base/ecs.h"
        "BreadEngineCore/src/Core/ECS/Base/vetterctor.h"
        "BreadEngineCore/src/Core/ECS/Components/animationcomponent.h"
        "BreadEngineCore/src/Core/ECS/Components/scriptcomponent.h"
        "BreadEngineCore/src/Core/ECS/Components/textlabelcomponent.h"
          "BreadEngineCore/src/Core/ECS/Systems/Animation/animationsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Animation/animationsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Camera/cameramovementsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Camera/cameramovementsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Movement/movementsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Movement/movementsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Physics/physicssystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Physics/physicssystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendercollidersystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendercollidersystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendersystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendersystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendertextsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendertextsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Script/scriptsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Script/scriptsystem.h"
      "BreadEngineCore/src/Core/EventBus/event.h"
      "BreadEngineCore/src/Core/EventBus/eventbus.h"
      "BreadEngineCore/src/Core/Logger/Logger.cpp"
      "BreadEngineCore/src/Core/Logger/Logger.h"
        "BreadEngineCore/src/Core/Render/PhysicsRenderer/SFMLDebugDraw.cpp"
        "BreadEngineCore/src/Core/Render/PhysicsRenderer/SFMLDebugDraw.h"
        "BreadEngineCore/src/Core/Render/Window/Window.cpp"
        "BreadEngineCore/src/Core/Render/Window/Window.h"
      "BreadEngineCore/src/Core/Scene/scenemanager.cpp"
      "BreadEngineCore/src/Core/Scene/scenemanager.h"
      "BreadEngineCore/src/Core/Serializer/XMLSerializator.cpp"
      "BreadEngineCore/src/Core/Serializer/XMLSerializator.h"
      "BreadEngineCore/src/Core/Serializer/serializer.cpp"
      "BreadEngineCore/src/Core/Serializer/serializer.h"
      "BreadEngineCore/src/Core/Serializer/tmxmapparser.cpp"
      "BreadEngineCore/src/Core/Serializer/tmxmapparser.h"
      "BreadEngineCore/src/Core/Util/util.cpp"
      "BreadEngineCore/src/Core/Util/util.h"
)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
  set_target_properties("BreadEngineCore" PROPERTIES
    OUTPUT_NAME "BreadEngineCore"
    ARCHIVE_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
    LIBRARY_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
    RUNTIME_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
  )
endif()
target_include_directories("BreadEngineCore" PRIVATE
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TinyXML/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/glm>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/SFML/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/Lua/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/sol>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/ImGUI/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/Box2D/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TmxParser/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TGUI/include>
)
target_compile_definitions("BreadEngineCore" PRIVATE
  $<$<CONFIG:Debug>:SFML_STATIC>
  $<$<CONFIG:Debug>:TGUI_STATIC>
  $<$<CONFIG:Debug>:DEBUG>
)
target_link_directories("BreadEngineCore" PUBLIC
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TinyXML/libs>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/SFML/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/Lua/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/ImGUI/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/Box2D/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TmxParser/libs>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TGUI/lib>
)
target_link_libraries("BreadEngineCore"
  $<$<CONFIG:Debug>:opengl32>
  $<$<CONFIG:Debug>:openal32>
  $<$<CONFIG:Debug>:freetype>
  $<$<CONFIG:Debug>:winmm>
  $<$<CONFIG:Debug>:gdi32>
  $<$<CONFIG:Debug>:flac>
  $<$<CONFIG:Debug>:vorbisenc>
  $<$<CONFIG:Debug>:vorbisfile>
  $<$<CONFIG:Debug>:vorbis>
  $<$<CONFIG:Debug>:ogg>
  $<$<CONFIG:Debug>:ws2_32>
  $<$<CONFIG:Debug>:liblua53>
  $<$<CONFIG:Debug>:sfml-graphics-s-d>
  $<$<CONFIG:Debug>:sfml-window-s-d>
  $<$<CONFIG:Debug>:sfml-system-s-d>
  $<$<CONFIG:Debug>:sfml-audio-s-d>
  $<$<CONFIG:Debug>:sfml-network-s-d>
  $<$<CONFIG:Debug>:sfml-main-d>
  $<$<CONFIG:Debug>:ImGUISNR-d>
  $<$<CONFIG:Debug>:tinyxml2d>
  $<$<CONFIG:Debug>:box2dd>
  $<$<CONFIG:Debug>:TmxParser-d>
  $<$<CONFIG:Debug>:tgui-s-d>
)
target_compile_options("BreadEngineCore" PRIVATE
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/MP>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/MDd>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/Z7>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/MP>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/MDd>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/Z7>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/EHsc>
)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
  set_target_properties("BreadEngineCore" PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
    POSITION_INDEPENDENT_CODE False
    INTERPROCEDURAL_OPTIMIZATION False
  )
endif()


texus

Are those the only linking errors, or just the first 10 out of a much longer list?

Can you try with placing the "$<$<CONFIG:Debug>:tgui-s-d>" line to above the "$<$<CONFIG:Debug>:sfml-graphics-s-d>" line? Especially for static libraries, you typically have to order the list so that if A depends on B then A should appear before B in the list.

If that doesn't fix it, then can you tell me which compiler and SFML and TGUI versions you are using?

Normally in CMake you would use find_package to search for SFML and TGUI and then you would only need `target_link_directories(BreadEngineCore PRIVATE sfml-graphics TGUI::TGUI)` to import all settings such as include directory, linker path, defines and dependency ordering. However the manual method that you are using should also work fine.

EngineerBread

Hi thank you for your answer, I followed your advice and yes, the problem was the version of SFML, seems like I had one from 2022, I updated to the most recent one and its working fine.