1

I have been trying to include Synthesis XSD into my project, but unfortunately, I have been dealing with a linking problem after I have generated my XML files into cxx files.

These are the lines in my CMakelist.txt files that should include and link the library into my executable. NOTES:

  • For simplicity, I have added a hardcoded path to the installation directory of Synthesis XSD 4.0
  • I have Box2D and SDL included into my project and they always have worked before. You can ignore them in this code
cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CURRENT_BINARY_DIR ./build)
set(CMAKE_CURRENT_SOURCE_DIR .)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

add_executable(NightByte ./Main.cpp
        # Game
        ./Game/Game.cpp
        ./Game/Components/Component.hpp
        ./Game/Components/RenderComponent.cpp
        ./Game/Components/RenderComponent.hpp
        ./Game/Components/WorldPositionComponent.cpp
        ./Game/Components/WorldPositionComponent.hpp
        ./Game/Scenes/Menu/MainMenu.hpp
        # Engine
        ./Engine/Engine.cpp
        ./Engine/Audio/AudioFile.cpp
        ./Engine/Audio/AudioFile.h
        ./Engine/Input/Adapter/SDLInputEngineAdapter.cpp
        ./Engine/Audio/Adapter/SDLAudioEngineAdapter.cpp
        ./Engine/Audio/Adapter/SDLAudioEngineAdapter.hpp
        ./Engine/Rendering/Spritesheet.cpp
        ./Engine/Rendering/TextureManager.cpp
        ./Engine/Rendering/Adapter/SDLRenderingAdaper.cpp
        # API
        ./API/Input/EngineInputAPI.cpp
        ./API/Audio/AudioAPI.cpp
        ./API/Rendering/EngineRenderingAPI.hpp
        ./API/Rendering/EngineRenderingAPI.cpp
        ./API/Engine/EngineWindowAPI.cpp
        ./API/Engine/WindowAPI.hpp
        # XML
        ./Engine/Resources/XML/Generated/wall.hxx
        ./Engine/Resources/XML/Generated/wall.cxx
        ./Engine/Resources/XML/Generated/common.hxx
        ./Engine/Resources/XML/Generated/common.cxx
        )

find_package(box2d REQUIRED)

target_include_directories(NightByte PUBLIC
        ${SDL2_SOURCE_DIR}/include
        ${BOX2D_SOURCE_DIR}/include/box2d
        ${SDL2IMAGE_SOURCE_DIR}
        "C:/Program Files (x86)/CodeSynthesis XSD 4.0/include/")

add_library(xerces "C:/Program Files (x86)/CodeSynthesis XSD 4.0/bin64/xerces-c_3_1D_vc120.dll"
        "C:/Program Files (x86)/CodeSynthesis XSD 4.0/bin64/xerces-c_3_1_vc120.dll"
        "C:/Program Files (x86)/CodeSynthesis XSD 4.0/lib64/vc-12.0/xerces-c_3.lib")

set_target_properties(xerces PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(NightByte SDL2 box2d SDL2::image xerces)

This is the error I get when compiling the generated XML files:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::initialize()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:84: undefined reference to `__imp__ZN11xercesc_3_16XMLUni22fgXercescDefaultLocaleE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:84: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils10InitializeEPKcS2_PNS_12PanicHandlerEPNS_13MemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::terminate()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:90: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils9TerminateEv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xercesc_3_1::DOMErrorHandler::DOMErrorHandler()':
C:/PROGRA~2/CODESY~1.0/include/xercesc/dom/DOMErrorHandler.hpp:54: undefined reference to `__imp__ZTVN11xercesc_3_115DOMErrorHandlerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xercesc_3_1::DOMErrorHandler::~DOMErrorHandler()':
C:/PROGRA~2/CODESY~1.0/include/xercesc/dom/DOMErrorHandler.hpp:77: undefined reference to `__imp__ZTVN11xercesc_3_115DOMErrorHandlerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_stream::std_input_stream(std::istream&)':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:27: undefined reference to `__imp__ZN11xercesc_3_114BinInputStreamC2Ev'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_source::std_input_source(std::istream&)':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:87: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:87: undefined reference to `__imp__ZN11xercesc_3_111InputSourceC2EPNS_13MemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_source::makeStream() const':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:141: undefined reference to `__imp__ZN11xercesc_3_17XMemorynwEy'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:141: undefined reference to `__imp__ZN11xercesc_3_17XMemorydlEPv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `std::unique_ptr<xercesc_3_1::DOMDocument, xsd::cxx::xml::dom::deleter<xercesc_3_1::DOMDocument> > xsd::cxx::xml::dom::create_document<char>()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/wildcard-source.txx:29: undefined reference to `__imp__ZN11xercesc_3_125DOMImplementationRegistry20getDOMImplementationEPKt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/wildcard-source.txx:32: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `std::unique_ptr<xercesc_3_1::DOMDocument, xsd::cxx::xml::dom::deleter<xercesc_3_1::DOMDocument> > xsd::cxx::xml::dom::parse<char>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, xercesc_3_1::DOMErrorHandler&, xsd::cxx::xml::properties<char> const&, unsigned long)':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:264: undefined reference to `__imp__ZN11xercesc_3_125DOMImplementationRegistry20getDOMImplementationEPKt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:266: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:273: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMCommentsE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:277: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgDOMDatatypeNormalizationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:284: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMEntitiesE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:288: undefined reference to `__imp__ZN11xercesc_3_16XMLUni15fgDOMNamespacesE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:292: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgDOMElementContentWhitespaceE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:296: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMValidateE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:297: undefined reference to `__imp__ZN11xercesc_3_16XMLUni14fgXercesSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:298: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgXercesSchemaFullCheckingE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:302: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMValidateE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:303: undefined reference to `__imp__ZN11xercesc_3_16XMLUni14fgXercesSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:310: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgXercesHandleMultipleImportsE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:317: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgXercesSchemaFullCheckingE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:322: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgXercesUserAdoptsDOMDocumentE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:333: undefined reference to `__imp__ZN11xercesc_3_16XMLUni36fgXercesSchemaExternalSchemaLocationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:343: undefined reference to `__imp__ZN11xercesc_3_16XMLUni47fgXercesSchemaExternalNoNameSpaceSchemaLocationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:355: undefined reference to `__imp__ZN11xercesc_3_16XMLUni18fgXercesLoadSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:361: undefined reference to `__imp__ZN11xercesc_3_16XMLUni17fgDOMErrorHandlerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_source::std_input_source<char>(std::istream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:102: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:102: undefined reference to `__imp__ZN11xercesc_3_111InputSourceC2EPKtPNS_13MemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `std::unique_ptr<xercesc_3_1::DOMDocument, xsd::cxx::xml::dom::deleter<xercesc_3_1::DOMDocument> > xsd::cxx::xml::dom::parse<char>(xercesc_3_1::InputSource&, xercesc_3_1::DOMErrorHandler&, xsd::cxx::xml::properties<char> const&, unsigned long)':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:120: undefined reference to `__imp__ZN11xercesc_3_125DOMImplementationRegistry20getDOMImplementationEPKt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:122: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:129: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMCommentsE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:133: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgDOMDatatypeNormalizationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:140: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMEntitiesE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:144: undefined reference to `__imp__ZN11xercesc_3_16XMLUni15fgDOMNamespacesE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:148: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgDOMElementContentWhitespaceE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:152: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMValidateE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:153: undefined reference to `__imp__ZN11xercesc_3_16XMLUni14fgXercesSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:154: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgXercesSchemaFullCheckingE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:158: undefined reference to `__imp__ZN11xercesc_3_16XMLUni13fgDOMValidateE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:159: undefined reference to `__imp__ZN11xercesc_3_16XMLUni14fgXercesSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:166: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgXercesHandleMultipleImportsE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:172: undefined reference to `__imp__ZN11xercesc_3_16XMLUni26fgXercesSchemaFullCheckingE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:177: undefined reference to `__imp__ZN11xercesc_3_16XMLUni29fgXercesUserAdoptsDOMDocumentE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:188: undefined reference to `__imp__ZN11xercesc_3_16XMLUni36fgXercesSchemaExternalSchemaLocationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:198: undefined reference to `__imp__ZN11xercesc_3_16XMLUni47fgXercesSchemaExternalNoNameSpaceSchemaLocationE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:210: undefined reference to `__imp__ZN11xercesc_3_16XMLUni18fgXercesLoadSchemaE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:216: undefined reference to `__imp__ZN11xercesc_3_16XMLUni17fgDOMErrorHandlerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:218: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils15fgMemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:218: undefined reference to `__imp__ZN11xercesc_3_119Wrapper4InputSourceC1EPNS_11InputSourceEbPNS_13MemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:218: undefined reference to `__imp__ZN11xercesc_3_119Wrapper4InputSourceD1Ev'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/dom/parsing-source.txx:218: undefined reference to `__imp__ZN11xercesc_3_119Wrapper4InputSourceD1Ev'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj):wall.cxx:(.rdata$_ZTVN3xsd3cxx3xml3sax16std_input_sourceE[_ZTVN3xsd3cxx3xml3sax16std_input_sourceE]+0x48): undefined reference to `xercesc_3_1::InputSource::setEncoding(unsigned short const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj):wall.cxx:(.rdata$_ZTVN3xsd3cxx3xml3sax16std_input_sourceE[_ZTVN3xsd3cxx3xml3sax16std_input_sourceE]+0x50): undefined reference to `xercesc_3_1::InputSource::setPublicId(unsigned short const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj):wall.cxx:(.rdata$_ZTVN3xsd3cxx3xml3sax16std_input_sourceE[_ZTVN3xsd3cxx3xml3sax16std_input_sourceE]+0x58): undefined reference to `xercesc_3_1::InputSource::setSystemId(unsigned short const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_source::~std_input_source()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:83: undefined reference to `__imp__ZN11xercesc_3_111InputSourceD2Ev'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_source::~std_input_source()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:83: undefined reference to `__imp__ZN11xercesc_3_17XMemorydlEPv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_stream::~std_input_stream()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:23: undefined reference to `__imp__ZN11xercesc_3_114BinInputStreamD2Ev'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::sax::std_input_stream::~std_input_stream()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/sax/std-input-source.hxx:23: undefined reference to `__imp__ZN11xercesc_3_17XMemorydlEPv'
collect2.exe: error: ld returned 1 exit status

Update 1:

To make the case easier to understand, I have added the .lib file for this library next to the DLL's enter image description here

Update 2:

I have changed the add_library to:

add_library(xerces SHARED IMPORTED GLOBAL)
set_target_properties(xerces PROPERTIES IMPORTED_IMPLIB "C:/Program Files (x86)/CodeSynthesis XSD 4.0/lib64/vc-12.0/xerces-c_3.lib")
set_target_properties(xerces PROPERTIES IMPORTED_LOCATION "C:/Program Files (x86)/CodeSynthesis XSD 4.0/bin64/xerces-c_3_1_vc120.dll")

target_link_libraries(NightByte SDL2 box2d SDL2::image xerces)

But I still get the same linking CXX executable error:

[100%] Linking CXX executable bin\NightByte.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::initialize()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:84: undefined reference to `__imp__ZN11xercesc_3_16XMLUni22fgXercescDefaultLocaleE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:84: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils10InitializeEPKcS2_PNS_12PanicHandlerEPNS_13MemoryManagerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xsd::cxx::xml::terminate()':
C:/PROGRA~2/CODESY~1.0/include/xsd/cxx/xml/elements.hxx:90: undefined reference to `__imp__ZN11xercesc_3_116XMLPlatformUtils9TerminateEv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xercesc_3_1::DOMErrorHandler::DOMErrorHandler()':
C:/PROGRA~2/CODESY~1.0/include/xercesc/dom/DOMErrorHandler.hpp:54: undefined reference to `__imp__ZTVN11xercesc_3_115DOMErrorHandlerE'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\NightByte.dir/objects.a(wall.cxx.obj): in function `xercesc_3_1::DOMErrorHandler::~DOMErrorHandler()':
C:/PROGRA~2/CODESY~1.0/include/xercesc/dom/DOMErrorHandler.hpp:77: undefined reference to `__imp__ZTVN11xercesc_3_115DOMErrorHandlerE'
[AND MORE]

Update 3

I have used find_package before and I am trying it now as well(As well the other method). But in this scenario, I receive the following error when linking in make:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find C:/Program Files (x86)/CodeSynthesis XSD 4.0: Permission denied

With Verbose=1 in Make

[other executions by make]

[ 44%] Built target box2d
C:/Users/husey/scoop/apps/make/current/bin/make.exe  -f CMakeFiles\NightByte.dir\build.make CMakeFiles/NightByte.dir/depend
make[2]: Entering directory 'C:/Users/husey/Desktop/engine/build'
D:\JetBrains\Toolbox\apps\CLion\ch-0\202.7660.37\bin\cmake\win\bin\cmake.exe -E cmake_depends "MinGW Makefiles" C:\Users\husey\Desktop\engine C:\Users\husey\Desktop\engine C:\Users\husey\Desktop\engine\build C:\Users\husey\Desktop\engine\build C:\Users\husey\Desktop\engine\build\CMakeFiles\NightByte.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'C:/Users/husey/Desktop/engine/build'
C:/Users/husey/scoop/apps/make/current/bin/make.exe  -f CMakeFiles\NightByte.dir\build.make CMakeFiles/NightByte.dir/build
make[2]: Entering directory 'C:/Users/husey/Desktop/engine/build'
[ 44%] Linking CXX executable bin\NightByte.exe
D:\JetBrains\Toolbox\apps\CLion\ch-0\202.7660.37\bin\cmake\win\bin\cmake.exe -E cmake_link_script CMakeFiles\NightByte.dir\link.txt --verbose=1
D:\JetBrains\Toolbox\apps\CLion\ch-0\202.7660.37\bin\cmake\win\bin\cmake.exe -E rm -f CMakeFiles\NightByte.dir/objects.a
C:\msys64\mingw64\bin\ar.exe cr CMakeFiles\NightByte.dir/objects.a @CMakeFiles\NightByte.dir\objects1.rsp
C:\msys64\mingw64\bin\g++.exe -g   -Wl,--whole-archive CMakeFiles\NightByte.dir/objects.a -Wl,--no-whole-archive  -o bin\NightByte.exe -Wl,--out-implib,libNightByte.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\NightByte.dir\linklibs.rsp
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find C:/Program Files (x86)/CodeSynthesis XSD 4.0: Permission denied
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles\NightByte.dir\build.make:366: bin/NightByte.exe] Error 1
make[2]: Leaving directory 'C:/Users/husey/Desktop/engine/build'
make[1]: *** [CMakeFiles\Makefile2:345: CMakeFiles/NightByte.dir/all] Error 2
make[1]: Leaving directory 'C:/Users/husey/Desktop/engine/build'
make: *** [Makefile:149: all] Error 2
Sakirma
  • 31
  • 1
  • 6
  • 1
    You probably wanted to create `xerces` library as [IMPORTED](https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries) one, so it would represent **already existed** library. See [that answer](https://stackoverflow.com/a/10550334/3440745) for more details about linking external libraries in CMake using that approach. – Tsyvarev Nov 05 '20 at 17:40
  • Thank you for your help @Tsyvarev, but unfortunately even though I looked into the links you have provided, I couldn't make it work. ```add_library(xerces SHARED IMPORTED GLOBAL) set_target_properties(xerces PROPERTIES IMPORTED_LOCATION "C:/Program Files (x86)/CodeSynthesis XSD 4.0/bin64/xerces-c_3_1D_vc120.dll") target_link_libraries(NightByte SDL2 box2d SDL2::image xerces)``` With this, it gives an error that it could not be found – Sakirma Nov 05 '20 at 18:21
  • When I use the shared dll's it can't find it, when I do static for the libs (Codesynthesis provides both) I will get the same linking error. – Sakirma Nov 05 '20 at 18:28
  • 1
    "it gives an error that it could not be found" - What **exact file** is reported as "not found"? `.dll` one or `.lib` one? If you have export file (`.lib`) for the shared library (`.dll`) not in the same directory, aside from setting `IMPORTED_LOCATION` property to `.dll` file you need to set [IMPORTED_IMPLIB](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_IMPLIB.html#prop_tgt:IMPORTED_IMPLIB) to the location of the `.lib` file. – Tsyvarev Nov 05 '20 at 18:37
  • To answer your question: For the DLL file. I will edit my question to show you how it looks now – Sakirma Nov 05 '20 at 18:47
  • 1
    Please, do not use *images* for show the *textual* information. Instead, **paste the text** into the question post. The error `cerces-NOTFOUND` is actually about some property which is not set for `cerces` library. As I said, you need to set `IMPORTED_IMPLIB` property. – Tsyvarev Nov 05 '20 at 19:06
  • Oh I am sorry, I thought this might have made it easier for anyone to read. Your solution fixed the part of `xerces-NOTFOUND` but now, I still get the linking error. I will update my question so it becomes easier for you to read. Thank you – Sakirma Nov 05 '20 at 19:18
  • The cause of the latest error is probably hidden somewhere within linklibs.rsp response file. Would you please provide the contents of a `CMakeFiles\NightByte.dir\linklibs.rsp` – gordan.sikic Nov 05 '20 at 20:45
  • Sure! `build/box2d/bin/libbox2d.a build/sdlimage/libSDL2_image.dll.a "C:/Program Files (x86)/CodeSynthesis XSD 4.0" -lwinpthread build/sdl/libSDL2d.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32` – Sakirma Nov 05 '20 at 20:49
  • 1
    You somehow managed to add `"C:/Program Files (x86)/CodeSynthesis XSD 4.0"` in place of the library. g++ tries to access this folder as it is a library (which is not possible), and hence the error. I'd suggest doing a "clean build" in the new build folder, and possibly to execute `cmake-gui .` within (original) build folder. remove all references to the folder in question, reconfigure and try building. – gordan.sikic Nov 05 '20 at 22:10
  • Hey @gordan.sikic, one question. I am using the CodeSynthesis XSD library which has already included that library. If I make CMake working with CodeSynthesis's Library, wouldn't that mean my linking problem will automatically be fixed? Or is this linking problem involved with the Xerces library only? – Sakirma Nov 05 '20 at 22:11
  • Yes, I will try that! Thank you! – Sakirma Nov 05 '20 at 22:11
  • 1
    IIRC, xsd is "header only", but depends on xerces library. Judging from the original problem it was "xerces specific"; everything was fine, up to the linking point. In brief, you have to link against the XercesC library. – gordan.sikic Nov 05 '20 at 22:15
  • Hey Gordan, I managed to fix that problem with setting the library for xercesc like so: `set(XercesC_LIBRARY "C:/Program Files (x86)/CodeSynthesis XSD 4.0/bin64/xerces-c_3_1_vc120.dll") find_package(XercesC REQUIRED) # XSD DEPENDS ON ${XERCESC_FOUND}` This solved the issue of the permission error, but I still receive the same linking error :( Thanks for the help though! Do you have any other suggestions? – Sakirma Nov 05 '20 at 22:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224170/discussion-between-huseyin-caliskan-and-gordan-sikic). – Sakirma Nov 05 '20 at 23:13

2 Answers2

1

For standard libraries like XercesC, CMake provides a standard way of "including" them into your project, i.e. find_package.

In your case, instead of manually adding_library, you should write something like this:

# omitted the first part of CMakeLists ....
 
find_package(box2d REQUIRED)
find_package(XercesC REQUIRED)

target_include_directories(NightByte PUBLIC
        ${SDL2_SOURCE_DIR}/include
        ${BOX2D_SOURCE_DIR}/include/box2d
        ${SDL2IMAGE_SOURCE_DIR}
        )

target_link_libraries(NightByte SDL2 box2d SDL2::image XercesC::XercesC)

Note the following:

  • XercesC is searched for the same way as box2d
  • NightByte target is linked against the XercesC::XercesC. This is imported library, that is created by FindXercesC.cmake in case xercesc is found.
  • explicitly adding XercexC include directories is not necessary, since all compiling attributes are inherited from XercesC::XercesC when you link against it.

BTW, there are a couple of other issues with your CMakeLists.txt. on lines 3 and 4 you explicitly set CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR. In brief, don't do it, CMake automatically takes care of the values of those variables.

In the end, here is the documentation about find_package, XercesC module, and a list of readily available parkages in CMake (scroll down to "Find Modules" for a list).

gordan.sikic
  • 1,174
  • 8
  • 8
  • Thank you for your answer, I am trying to solve this problem in many ways. I tried find_package as well but, I encountered `permission denied to the CodeSynthesis XSD 4.0 folder` error when I run Make. Is this something that you are familiar with? – Sakirma Nov 05 '20 at 19:24
  • you may also run make in a verbose mode, i.e. `make VERBOSE=1`. All building commands will be printed before execution, so you will very quickly find the offending command. – gordan.sikic Nov 05 '20 at 19:31
  • Thank you for your help Gordan. No I did not receive any errors when running cmake. I even tried to put the install folder into Desktop or any other location but this has failed as well. This is what I get with `Verbose=1`. I will update my question so you will be able to see it – Sakirma Nov 05 '20 at 19:37
0

Thank you guys for helping me out, without you I probably wouldn't have gotten further.

My problem was that I have been using the MinGW compiler but the CodeSynthesis libraries I got are built with Visual Studio's compiler.

I haven't been able to compile yet with MinGW but this problem is solved by using the Visual Studio Compiler.

For those who use the MinGW compiler, download the following: enter image description here

Sakirma
  • 31
  • 1
  • 6
  • I hope other people will find this solution too if they encounter this problem. Feedback to correct my question/solution is valued! – Sakirma Nov 06 '20 at 19:29