gpt4 book ai didi

c++ - 链接器错误编译 keyczar 程序

转载 作者:太空狗 更新时间:2023-10-29 11:46:04 31 4
gpt4 key购买 nike

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

#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 的教程

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

/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

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

最佳答案

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

g++ -o basic_encrypt -Wall -O2 base_encrypt.cpp -lkeyczar -lcrypto

关于c++ - 链接器错误编译 keyczar 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14465536/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com