Question

When i try to compile a simple test project using the static libraries i used before, i.e. Foundation,Net etc. Everything works fine but when i include the Crypto library i get loads of error, could it be caused by the openssl dependency? I've added the openssl include folder and the Poco Foundation,Net,Crypto as well as the .a files for Foundation,Net,Crypto to the build settings in XCode

The code:

//ViewController.h
 #include <Poco/Crypto/CipherFactory.h>
 #include <Poco/Crypto/Cipher.h>
 #include <Poco/Crypto/CipherKey.h>

In my 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()]);

The error messages:

  "_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)
Was it helpful?

Solution

Problem is not within your code actually. You need to use libcrypto.a or libssl.a which is build on exact same platform. Specially if you are using for iOS simulator that it will be for i386 or arm6 or arm7 in case of device. So, there should be platform specific library. You can have this library codes from websites and compile with same architecture or make a fat library that will be appropriate for multiple platform.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top