我目前正在尝试将C++lib与SWIG集成,SWIG是各种语言(UseSWIG)的包装器生成器。我想集成到golang中,为此,我正在使用cmake轻松构建它。我的 cmake 在我构建时正在工作,它会生成包装器文件和 go 文件,用于我的 go 模块。但在 MSVC 中,我从生成的文件中收到一些错误。我还尝试直接调用我的go模块(通过go run...),但它缺少libs,这就是为什么我选择首先使用Cmake构建它(链接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
1 回答
达令说
TA贡献1821条经验 获得超6个赞
找到了一种避免这些错误的方法,DLL正在为MSVC中的SWIG构建良好:
在 .i 文件的开头添加这些行:
%begin %{
#define __attribute__(x)
%}
%include <windows.i>
- 1 回答
- 0 关注
- 165 浏览
添加回答
举报
0/150
提交
取消