0

我一直在尝试实现运行时库,它是 CodeSynthesis 的仅标头库。但是,每当我尝试运行由 XSD 可执行文件生成的文件时,我只会收到链接编译错误。

这是向您显示运行时库的链接问题的错误:

[100%] Linking CXX executable XercesGebeuren.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::initialize()':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/elements.hxx:84: undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::terminate()':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/elements.hxx:90: undefined reference to `xercesc_3_2::XMLPlatformUtils::Terminate()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\XercesGebeuren.dir/objects.a(hello.cxx.obj): in function `xsd::cxx::xml::sax::std_input_stream::std_input_stream(std::istream&)':
C:/Users/husey/Desktop/XercesGebeuren/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/sax/std-input-source.hxx:27: undefined reference to `xercesc_3_2::BinInputStream::BinInputStream()'
---- [And so on] ----
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\XercesGebeuren.dir\build.make:122: XercesGebeuren.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:95: CMakeFiles/XercesGebeuren.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:102: CMakeFiles/XercesGebeuren.dir/rule] Error 2
mingw32-make: *** [Makefile:137: XercesGebeuren] Error 2

我已按照 CodeSynthesis 给出的指南使用以下命令生成我的 hello.cxx 和 hello.hxx 文件:xsd cxx-tree --std c++11 hello.xsd

制作

cmake_minimum_required(VERSION 3.17)
project(XercesGebeuren)

set(CMAKE_CXX_STANDARD 20)
set(Xsd_DIR ./cmake)

find_package(XercesC REQUIRED)
find_package(Xsd REQUIRED)

add_executable(XercesGebeuren main.cpp src/hello.cxx)

add_library(mylib INTERFACE)
target_include_directories(mylib PUBLIC INTERFACE "./libxsd/")

target_include_directories(XercesGebeuren PUBLIC ${XSD_INCLUDE_DIR})
target_link_libraries(XercesGebeuren PUBLIC mylib)
4

1 回答 1

1

感谢'Asteroids With Wings',我发现不应将仅标头库添加为 CMake 中的库。包括库和链接 XercesC 库就足够了。

CMake 解决方案

cmake_minimum_required(VERSION 3.17)
project(XercesGebeuren)

set(CMAKE_CXX_STANDARD 20)
set(Xsd_DIR ./cmake)

find_package(XercesC REQUIRED)
find_package(Xsd REQUIRED)

add_executable(XercesGebeuren main.cpp src/hello.cxx )

target_include_directories(XercesGebeuren PUBLIC ${XSD_INCLUDE_DIR})

target_link_libraries(XercesGebeuren PUBLIC XercesC::XercesC)
于 2020-11-07T21:45:52.153 回答