链接错误 cmake - 在 cmake 中使用 CodeSynthesis XSD

Linking Error cmake - Using CodeSynthesis XSD in cmake

我一直在尝试将 Synthesis XSD 包含到我的项目中,但不幸的是,在我将 XML 文件生成到 cxx 后,我一直在处理 linking 问题文件。

这些是我的 CMakelist.txt 文件中的行,应该将库 link 包含到我的可执行文件中。 注意:

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)

这是我在编译生成的 XML 文件时遇到的错误:

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

更新 1:

为了使案例更容易理解,我在 DLL 的旁边添加了该库的 .lib 文件

更新二:

我已将 add_library 更改为:

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)

但我仍然遇到相同的 linking CXX 可执行错误:

[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]

更新 3

我以前用过find_package,现在也在尝试(以及其他方法)。 但是在这种情况下,link 在 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

在 Make 中使用 Verbose=1

[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-02.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-02.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-02.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

对于像 XercesC 这样的标准库,CMake 提供了一种将它们“包含”到您的项目中的标准方法,即 find_package.

在你的情况下,而不是手动 adding_library,你应该这样写:

# 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)

注意以下几点:

  • XercesC 的搜索方式与 box2d
  • 相同
  • NightByte 目标是 link 针对 XercesC::XercesC 的。这是导入的库,由 FindXercesC.cmake 创建,以防找到 xercesc。
  • 不需要显式添加 XercexC 包含目录,因为当您 link 反对它时,所有编译属性都是从 XercesC::XercesC 继承的。

顺便说一句,您的 CMakeLists.txt 还有一些其他问题。在第 3 行和第 4 行,您明确设置了 CMAKE_CURRENT_SOURCE_DIRCMAKE_CURRENT_BINARY_DIR。简而言之,不要这样做,CMake 会自动处理这些变量的值。

最后,这里是 CMake 中关于 find_package, XercesC module, and a list of readily available parkages 的文档(向下滚动到“查找模块”以获得列表)。

谢谢你们帮助我,没有你们我可能不会走得更远。

我的问题是我一直在使用 MinGW 编译器,但我得到的 CodeSynthesis 库是用 Visual Studio 的编译器构建的。

我还无法使用 MinGW 进行编译,但使用 Visual Studio 编译器解决了这个问题。

使用MinGW编译器的朋友请下载: