首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >链接器编译keyczar程序时出错

链接器编译keyczar程序时出错
EN

Stack Overflow用户
提问于 2013-01-23 02:29:50
回答 1查看 274关注 0票数 2

我正在使用g++ -lkeyczar -lcrypto -o basic_encrypt -Wall -O2 base_encrypt.cpp编译以下代码:

代码语言:javascript
复制
#include <cassert>
#include <iostream>
#include <string>
#include <keyczar/keyczar.h>

void EncryptAndDecrypt(const std::string& location) {
  keyczar::Keyczar* crypter = keyczar::Crypter::Read(location);
  if (!crypter)
    return;

  std::string input = "Secret message";
  std::string ciphertext;
  std::cout << "Plaintext: " << input << std::endl;

  bool result = crypter->Encrypt(input, &ciphertext);
  if (result) {
    std::cout << "Ciphertext (Base64w): " << ciphertext << std::endl;
    std::string decrypted_input;
    bool result = crypter->Decrypt(ciphertext, &decrypted_input);
    if (result)
      assert(input == decrypted_input);
  }
  delete crypter;
}

int main(int argc, char** argv) {
  if (argc != 2) {
    std::cout << "An absolute key set location must be provided as argument"
              << std::endl;
    return 1;  // error
  }

  // The first argument must represent the keyset's location
  const std::string location(argv[1]);

  EncryptAndDecrypt(location);
  return 0;
}

这是取自here的教程

但是,我遇到了以下错误:

代码语言:javascript
复制
/tmp/ccNlack3.o: In function `EncryptAndDecrypt(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
base_encrypt.cpp:(.text+0xf): undefined reference to `keyczar::Crypter::Read(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: ld returned 1 exit status

我无法解决这个问题,因为我知道我已经在编译时给出了库标志。为什么仍然无法正确链接?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-23 02:34:29

将库标志放在命令行的末尾:

代码语言:javascript
复制
g++ -o basic_encrypt -Wall -O2 base_encrypt.cpp -lkeyczar -lcrypto
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14465536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档