【问题标题】:CMake & CodeSynthesis Header-only library not compilingCMake & CodeSynthesis 仅标头库未编译
【发布时间】:2021-02-20 05:35:52
【问题描述】:

我一直在尝试实现运行时库,它是 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

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)

【问题讨论】:

  • 我很困惑。如果它是一个只有头文件的库,你不需要编译它(除了你自己文件中的#included 源代码)。 hello.xsd 是什么?你到底想做什么?这里正在建造什么?
  • 您先生是个天才。我不必将它添加到 CMake 示例中所示的库中!
  • @AsteroidsWithWings 解决方案是删除 add_library 和与其相关的任何内容,并将库 XercesC::XercesC 作为目标链接到项目。 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)

标签: c++ cmake codesynthesis


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多