2013-04-17 38 views
0

當我嘗試使用之前使用的靜態庫(即Foundation,Net等)編譯一個簡單的測試項目時,一切正常,但是當我包含Crypto庫時,的錯誤,可能是由openssl依賴造成的嗎?我已經添加了OpenSSL的包括文件夾和波科基金會網,加密,以及在XCode中Poco C++ Crypto靜態庫用法在XCode上生成錯誤

的.a文件爲基礎,網絡,加密,以生成設置代碼:

//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) 
+1

既然你接受pcbabu的答案,它看起來像你正在爲iOS構建。在這種情況下,您可以在[openssl-1.0.1e-ios](https://github.com/noloader/openssl-1.0.1e-ios)上爲iOS預建多主題OpenSSL庫。它有四種架構:ARMv7,ARMv7s,ARM64和i386模擬器。 – jww

回答

1

問題是不是你的代碼中實際。您需要使用基於完全相同平臺的libcrypto.alibssl.a。特別是如果您使用的是iOS模擬器,那麼在設備情況下,它將用於i386arm6 or arm7。所以,應該有平臺專用庫。您可以從網站獲得該庫代碼並使用相同的體系結構進行編譯,或製作一個適用於多平臺的胖庫。

+0

是否使用此命令配置了必要的版本:./configure --config = iPhoneSimulator --no-samples --no-tests --omit = CppParser,CodeGeneration,Remoting/RemoteGen,NetSSL_OpenSSL,Data/ODBC,Data/MySQL --include -path =/Users/exjobb/Downloads/openssl -1.0.1e/include –

+0

可以從命令行執行。請按照此[鏈接](http://x2on.de/2010/07/13/tutorial-iphone-app-with-compiled-openssl-1-0-0a-library/)。檢查你的配置命令是否正確與鏈接。 – pcbabu