【问题标题】:How to build Google tink library using bazel in C++?如何在 C++ 中使用 bazel 构建 Google tink 库?
【发布时间】:2021-03-04 07:13:41
【问题描述】:

我想为我的应用使用 Google tink 库。我使用 android ndk 绑定了我的代码。但是,我无法使用 bazel 构建 Google tink 库。我在 github (https://github.com/google/tink) 上试过他们的例子。此外,我对bazel 没有任何经验。因此,如果有人知道如何以任何方式构建 Google tink 库,我也对这些选项持开放态度。

我正在使用:

  • Ubuntu 20.04
  • 巴泽尔 3.1.0
  • gcc 版本是 9.3.0

我曾尝试关注https://github.com/google/tink/blob/master/examples/cc/helloworld/README.md,但结果出错:

bazel build ...

Starting local Bazel server and connecting to it...
ERROR: error loading package 'javascript/aead/internal': Unable to find package for @npm//@bazel/typescript:index.bzl: The repository '@npm' could not be resolved.
INFO: Elapsed time: 6.455s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
    currently loading: javascript/binary ... (6 packages)

【问题讨论】:

  • “我无法使用 bazel 构建 google tink 库。” - 请更新问题帖子,说明您尝试过的实际情况以及您得到的确切错误消息
  • 我编辑了我的问题。你可以检查一下谢谢。
  • @Savrona:请注意,在 Stack Overflow 上,问题不是“聊天”。完全允许编辑问题,但每次编辑后问题应该是完整并且无需阅读 cmets 即可理解。我已经编辑了您的问题并将自述文件的链接合并到其中。如果在当前形式中问题帖子中的描述与您的意图相矛盾,请随时对其进行编辑。

标签: c++ bazel tink


【解决方案1】:

编写README.md 时,整个项目都在一个Bazel workspace 中。现在examples 子目录是它自己独立的工作空间,所以你需要在执行bazel 之前将cd 放入其中。

正确说明:

# Build the code.
git clone https://github.com/google/tink
cd tink/examples/cc
bazel build ...

# Create some input.
echo "some plaintext" > foo.txt

# Encrypt.
./bazel-bin/helloworld/hello_world ./helloworld/aes128_gcm_test_keyset_json.txt \
    encrypt foo.txt "some aad" foo.encrypted

# Decrypt.
./bazel-bin/helloworld/hello_world ./helloworld/aes128_gcm_test_keyset_json.txt \
    decrypt foo.encrypted "some aad" foo-decrypted.txt

# Inspect the output.
cat foo-decrypted.txt

注意,the C++ implementation also supports using CMake,根据您的目的可能更容易升级。

【讨论】:

  • 谢谢。您的指示帮助我用 bazel 构建示例,正如您所说,cmake 对我来说更好。事实上,我设法以某种方式用 cmake 构建它。但我不知道为什么当我尝试 auto status = crypto::tink::TinkConfig::Register();auto status = crypto::tink::AeadConfig::Register(); 时它会给出错误的 std::bad_alloc。
  • 如果没有更多上下文(即您的代码以及您如何构建它),很难提供帮助。随意提出另一个问题或在 GitHub 存储库中打开一个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多