当我尝试使用我之前使用的静态库(即Foundation,Net等)编译一个简单的测试项目。一切正常但是当我包含Crypto库时我会收到大量错误,可能是由openssl依赖引起的?我已经将openssl include文件夹和Poco Foundation,Net,Crypto以及Foundation,Net,Crypto的.a文件添加到XCode中的构建设置
代码:
//ViewController.h
#include <Poco/Crypto/CipherFactory.h>
#include <Poco/Crypto/Cipher.h>
#include <Poco/Crypto/CipherKey.h>
在我的ViewDidLoad中:
//ViewController.mm
std::string headKey = "TESTSTRING";
// encode the string
CipherFactory& factory = CipherFactory::defaultFactory();
// Creates a 256-bit AES cipher
Cipher* pCipher = factory.createCipher(CipherKey("aes-256"));
std::string encrypted = pCipher->encryptString(headKey, Cipher::ENC_BASE64);
std::string decrypted = pCipher->decryptString(encrypted, Cipher::ENC_BASE64);
NSLog([NSString stringWithUTF8String:encrypted.c_str()]);
错误消息:
"_BIO_ctrl", referenced from:
"_BIO_free", referenced from:
"_BIO_new", referenced from:
"_BIO_new_mem_buf", referenced from:
"_BIO_s_file", referenced from:
"_BIO_s_mem", referenced from:
"_BN_bn2bin", referenced from:
"_BN_free", referenced from:
"_BN_new", referenced from:
"_BN_num_bits", referenced from:
"_BN_set_word", referenced from:
"_CRYPTO_num_locks", referenced from:
"_CRYPTO_set_dynlock_create_callback", referenced from:
"_CRYPTO_set_dynlock_destroy_callback", referenced from:
"_CRYPTO_set_dynlock_lock_callback", referenced from:
"_CRYPTO_set_id_callback", referenced from:
"_CRYPTO_set_locking_callback", referenced from:
"_ERR_error_string", referenced from:
"_ERR_free_strings", referenced from:
"_ERR_get_error", referenced from:
"_EVP_BytesToKey", referenced from:
"_EVP_CIPHER_CTX_block_size", referenced from:
"_EVP_CIPHER_CTX_cleanup", referenced from:
"_EVP_CIPHER_CTX_set_padding", referenced from:
"_EVP_CIPHER_block_size", referenced from:
"_EVP_CIPHER_flags", referenced from:
"_EVP_CIPHER_iv_length", referenced from:
"_EVP_CIPHER_key_length", referenced from:
"_EVP_CipherFinal_ex", referenced from:
"_EVP_CipherInit", referenced from:
"_EVP_CipherUpdate", referenced from:
"_EVP_PKEY_get1_RSA", referenced from:
"_EVP_cleanup", referenced from:
"_EVP_des_ede3_cbc", referenced from:
"_EVP_get_cipherbyname", referenced from:
"_EVP_md5", referenced from:
"_OPENSSL_add_all_algorithms_noconf", referenced from:
"_OPENSSL_config", referenced from:
"_PEM_read_bio_RSAPrivateKey", referenced from:
"_PEM_read_bio_RSAPublicKey", referenced from:
"_PEM_read_bio_RSA_PUBKEY", referenced from:
"_PEM_write_bio_RSAPrivateKey", referenced from:
"_PEM_write_bio_RSAPublicKey", referenced from:
"_RAND_seed", referenced from:
"_RSA_free", referenced from:
"_RSA_generate_key_ex", referenced from:
"_RSA_new", referenced from:
"_RSA_private_decrypt", referenced from:
"_RSA_public_encrypt", referenced from:
"_RSA_size", referenced from:
"_SSL_library_init", referenced from:
"_SSL_load_error_strings", referenced from:
"_X509_get_pubkey", referenced from:
"Poco::Crypto::CipherKey::CipherKey(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
"std::istream::gcount() const", referenced from:
"std::string::at(unsigned long) const", referenced from:
"std::string::data() const", referenced from:
"std::string::size() const", referenced from:
"std::string::c_str() const", referenced from:
"std::string::empty() const", referenced from:
"std::string::length() const", referenced from:
"std::string::operator[](unsigned long) const", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::gptr() const", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::pptr() const", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::eback() const", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::egptr() const", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::pbase() const", referenced from:
"std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:
"std::basic_ios<char, std::char_traits<char> >::good() const", referenced from:
"std::basic_ios<char, std::char_traits<char> >::rdbuf() const", referenced from:
"std::basic_ios<char, std::char_traits<char> >::operator void*() const", referenced from:
"std::allocator<char>::std::allocator()", referenced from:
"std::allocator<char>::~std::allocator()", referenced from:
"std::istream::get(char&)", referenced from:
"std::istream::get()", referenced from:
"std::istream::read(char*, int)", referenced from:
"std::istream::std::istream(std::basic_streambuf<char, std::char_traits<char> >*)", referenced from:
"std::istream::~std::istream()", referenced from:
"std::ostream::put(char)", referenced from:
"std::ostream::write(char const*, int)", referenced from:
"std::ostream::std::ostream(std::basic_streambuf<char, std::char_traits<char> >*)", referenced from:
"std::ostream::~std::ostream()", referenced from:
"std::ostream::operator<<(int)", referenced from:
"std::string::append(char const*)", referenced from:
"std::string::append(char const*, unsigned long)", referenced from:
"std::string::append(std::string const&)", referenced from:
"std::string::reserve(unsigned long)", referenced from:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced from:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
"std::string::operator=(std::string const&)", referenced from:
"std::string::operator+=(char)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::setg(char*, char*, char*)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::setp(char*, char*)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::sync()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::imbue(std::locale const&)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::pbump(int)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::sputc(char)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::uflow()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::sbumpc()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::setbuf(char*, int)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::xsgetn(char*, int)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::pubsync()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::seekoff(long long, std::_Ios_Seekdir, std::_Ios_Openmode)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::seekpos(std::fpos<__mbstate_t>, std::_Ios_Openmode)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::pbackfail(int)", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::showmanyc()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::basic_streambuf()", referenced from:
"std::basic_streambuf<char, std::char_traits<char> >::~basic_streambuf()", referenced from:
"std::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >::basic_istringstream(std::string const&, std::_Ios_Openmode)", referenced from:
"std::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_istringstream()", referenced from:
"std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)", referenced from:
"std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()", referenced from:
"std::ios_base::Init::Init()", referenced from:
"std::ios_base::Init::~Init()", referenced from:
"std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)", referenced from:
"std::basic_ios<char, std::char_traits<char> >::basic_ios()", referenced from:
"std::basic_ios<char, std::char_traits<char> >::~basic_ios()", referenced from:
"std::_Rb_tree_decrement(std::_Rb_tree_node_base*)", referenced from:
"std::_Rb_tree_increment(std::_Rb_tree_node_base*)", referenced from:
"std::__throw_length_error(char const*)", referenced from:
"std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)", referenced from:
"typeinfo for std::istream", referenced from:
"typeinfo for std::ostream", referenced from:
"typeinfo for std::basic_streambuf<char, std::char_traits<char> >", referenced from:
"typeinfo for std::basic_ios<char, std::char_traits<char> >", referenced from:
"non-virtual thunk to std::istream::~std::istream()", referenced from:
"non-virtual thunk to std::ostream::~std::ostream()", referenced from:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
答案 0 :(得分:1)
实际上问题不在你的代码中。您需要使用构建在完全相同平台上的libcrypto.a
或libssl.a
。特别是如果您使用的是iOS模拟器,那么在设备的情况下它将用于i386
或arm6 or arm7
。所以,应该有平台特定的库。您可以从网站获取此库代码并使用相同的体系结构进行编译,或者创建适合多平台的胖库。