我目前正在嘗試將C++lib與SWIG集成,SWIG是各種語言(UseSWIG)的包裝器生成器。我想集成到golang中,為此,我正在使用cmake輕松構(gòu)建它。我的 cmake 在我構(gòu)建時正在工作,它會生成包裝器文件和 go 文件,用于我的 go 模塊。但在 MSVC 中,我從生成的文件中收到一些錯誤。我還嘗試直接調(diào)用我的go模塊(通過go run...),但它缺少libs,這就是為什么我選擇首先使用Cmake構(gòu)建它(鏈接ext libs等),例如鏈接哪個是通過cmake中的vcpkg獲得的。<fmt/format.h>CMakeLists:......# SWIG integrationfind_package(SWIG 4.0.2)if(SWIG_FOUND) message("Swig integration") include (UseSWIG) set(IPATH "go-integration/basic_host") set (SWIG_FILE "basic_host.i") set_source_files_properties(${IPATH}/${SWIG_FILE} PROPERTIES CPLUSPLUS ON) #library for Go find_program(GO_EXECUTABLE go) if (GO_EXECUTABLE) message("Bindings for Go will be generated using ${GO_EXECUTABLE}") set(SWIG_MODULE_NAME "bhost-go") set(CMAKE_SWIG_FLAGS -c++ -go -cgo -intgosize 64) message("CMAKE_SWIG_FLAGS: ${CMAKE_SWIG_FLAGS}") swig_add_library(${SWIG_MODULE_NAME} TYPE SHARED LANGUAGE go OUTPUT_DIR basic_host SOURCES ${IPATH}/${SWIG_FILE} ) target_include_directories(${SWIG_MODULE_NAME} PRIVATE ${HIDAPI_INCLUDE_DIR}) swig_link_libraries(${SWIG_MODULE_NAME} PUBLIC stduuid) swig_link_libraries(${SWIG_MODULE_NAME} PUBLIC fmt::fmt-header-only) swig_link_libraries(${SWIG_MODULE_NAME} PUBLIC nlohmann_json nlohmann_json::nlohmann_json) set_target_properties(${SWIG_MODULE_NAME} PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) else() message("Go executable not found, golang integration not done") endif()else() message("Swig not found, integration not done")endif()basic_host.i%module basic_host%{ #include <atomic> #include <map> #include <memory> #include <iostream> #include <fmt/format.h> #include "../../examples/basic_host/command_line.h" #include "../../examples/basic_host/command_line.cpp"%}%include <std_string.i>%include "../../examples/basic_host/command_line.h"basic_host.go
帶有Swig和go-integration包裝器錯誤的Cmake
慕尼黑8549860
2022-08-15 15:41:26