链接器错误编译keyczar程序

我正在使用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; } 

这是从这里采取的教程

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

 /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