【发布时间】:2022-01-14 03:06:27
【问题描述】:
我有一个 cpp 项目,我想从源代码构建所有内容,以获取最新的东西。所以在我的项目根目录下,我创建了一个 3rd_party 文件夹并组装以下脚本:
sudo apt-get install autoconf automake libtool curl make g++ unzip -y
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig
cd ..
echo installing grpc
git clone --recurse-submodules -b v1.43.0 https://github.com/grpc/grpc
export MY_INSTALL_DIR=$HOME/.local
be sure that its exists
cd grpc
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ../..
make -j
make install
popd
我遇到了以下缺陷:
- grpc v1.43.0 克隆 3rd 方子模块 protoc v3.18,在构建后出现问题 - protoc 二进制在尝试生成时显示“找不到 cpp 插件”
为了克服我已经将脚本第一部分中获得的源代码复制到第二部分的第 3 方子文件夹,以确保它是 3.19 - 然后在编译协议工作正常之后,插件就位,并且 grpc 已链接针对最新版本。
非常奇怪的问题,需要了解为什么它会克隆过时的版本,以及为什么 3.18 在与 3.19 相同的构建参数下没有插件
-
在 cmakelists 中
find_package(Protobuf REQUIRED)完全失败 -
find_package( gRPC REQUIRED ) 运行不正常:
Found package configuration file:
[cmake]
[cmake] /home/a/.local/lib/cmake/grpc/gRPCConfig.cmake
[cmake]
[cmake] but it set gRPC_FOUND to FALSE so package "gRPC" is considered to be NOT
[cmake] FOUND. Reason given by package:
[cmake]
[cmake] The following imported targets are referenced, but are missing:
[cmake] protobuf::libprotobuf protobuf::libprotoc
问题
我如何编写脚本,在一个空文件夹中可以获取项目所需的所有与 grpc 3rd 方库和工具相关的内容?
【问题讨论】:
-
为什么不使用 CMake FetchContent() 来获取所有第三方?
-
@Mizux - FetchContent 有很多缺点......在许多公司环境中,需要互联网连接来构建是绝对不可能的,但更糟糕的是 FetchContent 意味着导入其他人的CMake 代码到你的构建中,它可以做任何事情......你必须仔细阅读它才能找到。
标签: c++ cmake protocol-buffers grpc