You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake+SWIG生成Go可用.dll时vcpkg安装Arrow失败求助

问题:添加SWIG配置后第三方库无法识别,Arrow库重装失败

我需要创建可在Go中使用的.dll文件,采用CMake+Visual Studio开发,流程是先在C++中编写并测试库,再通过SWIG和CMake生成Go模块处理依赖。但在CMakeLists.txt中添加SWIG相关配置后,已安装的第三方库无法被代码识别;尝试卸载重装库时,始终无法完成Arrow库的安装,报错信息如下:

CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:134 (message):
    Command failed: "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" --build . --config Release --target install -- -v -j9
    Working Directory: C:/Users/v-omarkhalil/Desktop/Work/VCPKG/vcpkg/buildtrees/arrow/x64-windows-rel
    See logs for more information:
      C:\Users\v-omarkhalil\Desktop\Work\VCPKG\vcpkg\buildtrees\arrow\install-x64-windows-rel-out.log

Call Stack (most recent call first):
  installed/x64-windows/share/vcpkg-cmake/vcpkg_cmake_build.cmake:74 (vcpkg_execute_build_process)
  installed/x64-windows/share/vcpkg-cmake/vcpkg_cmake_install.cmake:16 (vcpkg_cmake_build)
  ports/arrow/portfile.cmake:66 (vcpkg_cmake_install)
  scripts/ports.cmake:147 (include)


error: building arrow:x64-windows failed with: BUILD_FAILED
Elapsed time to handle arrow:x64-windows: 11 min
Please ensure you're using the latest port files with `git pull` and `vcpkg update`.
Then check for known issues at:
    https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+arrow
You can submit a new issue at:
    https://github.com/microsoft/vcpkg/issues/new?title=[arrow]+Build+error&body=Copy+issue+body+from+C%3A%2FUsers%2Fv-omarkhalil%2FDesktop%2FWork%2FVCPKG%2Fvcpkg%2Finstalled%2Fvcpkg%2Fissue_body.md

我的CMakeLists.txt内容如下:

# CMakeList.txt : CMake project for BlobConnectionTestCmake, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)

# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
 
project ("BlobConnectionTestCmake")
set(GO_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/go-modules")
set_property(GLOBAL PROPERTY GO_MODULE_DIRECTORY ${GO_MODULE_DIRECTORY})
file(MAKE_DIRECTORY ${GO_MODULE_DIRECTORY})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_library(Azure_connector SHARED "BlobConnectionTestCmake.cpp" "BlobConnectionTestCmake.h" "ConnectionHeader.hpp")

# Add source to this project's executable.
add_executable (BlobConnectionTestCmake2 "BlobConnectionTestCmake.cpp" "BlobConnectionTestCmake.h" "ConnectionHeader.hpp")

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET BlobConnectionTestCmake2 PROPERTY CXX_STANDARD 20)
endif()

# TODO: Add tests and install targets if needed.
    find_package(Arrow CONFIG REQUIRED)
    target_link_libraries(BlobConnectionTestCmake2 PRIVATE "$<IF:$<BOOL:${ARROW_BUILD_STATIC}>,Arrow::arrow_static,Arrow::arrow_shared>")

    find_package(Parquet CONFIG REQUIRED)
    target_link_libraries(BlobConnectionTestCmake2 PRIVATE "$<IF:$<BOOL:${ARROW_BUILD_STATIC}>,Parquet::parquet_static,Parquet::parquet_shared>")

  find_package(azure-storage-blobs-cpp REQUIRED)
  target_link_libraries(BlobConnectionTestCmake2 PRIVATE Azure::azure-storage-blobs)

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

swig_add_library(Azure_connector_swig TYPE SHARED LANGUAGE go SOURCES Azure_exp_connector.i)
swig_link_libraries(Azure_connector_swig Azure_connector)

find_package(Arrow REQUIRED)
swig_link_libraries(Azure_connector_swig "$<IF:$<BOOL:${ARROW_BUILD_STATIC}>,Arrow::arrow_static,Arrow::arrow_shared>")

find_package(Parquet REQUIRED)
swig_link_libraries(Azure_connector_swig "$<IF:$<BOOL:${ARROW_BUILD_STATIC}>,Parquet::parquet_static,Parquet::parquet_shared>")

find_package(azure-storage-blobs-cpp REQUIRED)
swig_link_libraries(Azure_connector_swig  Azure::azure-storage-blobs)

解决思路

1. 排查vcpkg环境与Arrow安装失败原因

  • 执行git pull更新vcpkg仓库,再运行vcpkg update同步最新端口文件,确保使用官方最新的Arrow编译配置
  • 查看install-x64-windows-rel-out.log的详细内容,日志会明确标注编译失败的具体原因(如依赖缺失、编译器参数错误、磁盘空间不足、网络问题导致依赖下载失败等)
  • 清理vcpkg缓存:删除vcpkg/buildtrees/arrow和vcpkg/packages/arrow*目录,再重新尝试安装

2. 修复CMakeLists.txt的配置问题

  • 避免重复调用find_package:将find_package(Arrow CONFIG REQUIRED)、find_package(Parquet CONFIG REQUIRED)、find_package(azure-storage-blobs-cpp REQUIRED)统一放在项目开头,重复查找可能导致变量冲突或识别异常
  • 为SWIG目标添加头文件包含目录:添加target_include_directories(Azure_connector_swig PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}),确保SWIG能正确找到项目头文件
  • 检查目标链接的一致性:确认Azure_connector库也链接了所需的第三方库,因为SWIG生成的库依赖Azure_connector,如果原库未链接依赖,SWIG库也会找不到相关符号

3. 解决第三方库识别问题

  • 确认CMake配置时指定了vcpkg工具链文件:在VS或CMake命令行中,添加-DCMAKE_TOOLCHAIN_FILE=[你的vcpkg路径]/scripts/buildsystems/vcpkg.cmake,确保CMake使用vcpkg管理的库
  • 检查编译目标triplet一致性:确保项目编译目标为x64-windows,与vcpkg安装的库的triplet一致(可通过vcpkg list查看已安装库的triplet)

4. Arrow安装临时方案

  • 尝试安装特定稳定版本的Arrow:例如vcpkg install arrow:x64-windows --version=15.0.0,避开最新版本可能存在的编译问题
  • 禁用Arrow的可选组件:如果不需要全部功能,可通过vcpkg特性参数减少编译负担,例如vcpkg install arrow:x64-windows --features=core,parquet

内容的提问来源于stack exchange,提问作者Omar Khalil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 08:37:21