google-cloud-cpp Speech模块CMake构建失败求助
问题描述
- 已完成google-cloud-cpp所有依赖安装,使用vcpkg作为包管理工具
- 在Speech模块的quickstart目录执行CMake配置命令时失败,报错如下:
-- Found RE2 via CMake. CMake Error at /root/vcpkg/scripts/buildsystems/vcpkg.cmake:613 (_add_library): _add_library cannot create ALIAS target "google-cloud-cpp::experimental-speech" because target "google-cloud-cpp::speech" is IMPORTED. Call Stack (most recent call first): /root/vcpkg/installed/x64-linux/share/google_cloud_cpp_speech/google_cloud_cpp_speech-config.cmake:25 (add_library) /root/vcpkg/scripts/buildsystems/vcpkg.cmake:824 (_find_package) CMakeLists.txt:21 (find_package)
- 使用的CMake命令:
cmake -H. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake
- 但在google-cloud-cpp主目录执行相同命令可正常完成配置,输出如下:
root@jioeva-cas-dev-2:~/google-cloud-cpp# cmake -H. -B.build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake -- Doxygen generation only enabled for cmake 3.9 and higher -- CURL linkage will be non-static -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- Doxygen generation only enabled for cmake 3.9 and higher -- CURL linkage will be non-static -- CURL linkage will be non-static -- Configuring done -- Generating done -- Build files have been written to: /root/google-cloud-cpp/.build
解决方案
方案1:直接在主项目中构建quickstart
因为主项目能正常完成CMake配置,可直接在主项目的构建目录中编译quickstart:
- 进入google-cloud-cpp主目录,确保已完成CMake配置(如你之前操作的那样)
- 执行构建命令时指定quickstart目标:
cmake --build .build --target speech_quickstart
- 构建完成后,可在
.build/google/cloud/speech/quickstart目录下找到可执行文件
方案2:升级CMake版本
该报错核心原因是CMake版本过低,CMake 3.11及以上版本才支持为IMPORTED目标创建ALIAS别名。操作步骤:
- 检查当前CMake版本:
cmake --version
- 如果版本低于3.11,通过包管理器(如apt、yum)或官方源码升级到3.11+版本
- 重新在quickstart目录执行原CMake命令
方案3:修改vcpkg的配置文件(临时 workaround)
如果暂时无法升级CMake,可修改vcpkg安装的speech配置文件,跳过别名创建:
- 打开
/root/vcpkg/installed/x64-linux/share/google_cloud_cpp_speech/google_cloud_cpp_speech-config.cmake文件 - 找到第25行附近的以下代码:
add_library(google-cloud-cpp::experimental-speech ALIAS google-cloud-cpp::speech)
- 将这一行注释掉(在行首加
#) - 重新在quickstart目录执行CMake命令
方案4:调整quickstart的CMakeLists.txt
修改quickstart目录下的CMakeLists.txt,直接使用原目标而非别名:
- 打开quickstart目录的
CMakeLists.txt - 找到链接目标的代码行,将
google-cloud-cpp::experimental-speech替换为google-cloud-cpp::speech - 重新执行CMake配置命令
内容的提问来源于stack exchange,提问作者vaib
相关产品推荐
相关产品推荐

