Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linking with openssl lib statically

I've build openssl manually (static libraries) following this guide now when I try to link my MFC test app with libeay32.lib I get following errors:

1>Linking...
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFreeCertificateContext@4 referenced in function _capi_free_key
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertGetCertificateContextProperty@16 referenced in function _capi_get_prov_info
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertOpenStore@20 referenced in function _capi_open_store
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFindCertificateInStore@24 referenced in function _capi_find_cert
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertEnumCertificatesInStore@8 referenced in function _capi_find_cert
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertCloseStore@8 referenced in function _capi_find_key
1>libeay32.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertDuplicateCertificateContext@4 referenced in function _capi_load_ssl_client_cert

Any advice? Thanks in advance.

EDIT: I’ve used OpenSSL 1.0.1t source code and Visual Studio 2008 command prompt for building 32 bit static libraries (I had no success with 1.0.2h version). My test app works fine when linking dynamically but I want to be able to link with static lib’s. I’m using OpenSSL for EVP Symmetric Encryption and Decryption

like image 803
cagi Avatar asked May 30 '16 09:05

cagi


People also ask

How do I view the contents of a static library?

I just discovered that you can use readelf -a to display the contents of all the object files in a static library. Invoke the readelf command like this: $ readelf -a mystaticlib.

What is Lcrypto?

lcrypto means to include libcrypto.s* -l is the name of the lib excluding the prefix "lib" and the ending .so or .sa. - L/usr/local/lib means the Path where to look for the lib specified with the -l flag. The error message means it cant find libcrypto.so in the specified dirs.

What does it mean to statically link?

Static linking means that the code for all routines called by your program becomes part of the executable file. Statically linked programs can be moved to run on systems without the XL Fortran runtime libraries.


1 Answers

when I try to link my MFC test app with libeay32.lib I get following errors...

You need to configure with enable-capieng. Also see Compilation and Installation on the OpenSSL wiki and How to use CAPI engine in OpenSSL mailing list archive.

error LNK2019: unresolved external symbol __imp__CertFreeCertificateContext@4 referenced in function _capi_free_key 
...

Once configured properly, you need to link against Windows' crypt32.lib library. See, for example, CertFreeCertificateContext functions. On Windows, it should be enough to add the following to your MSVC source file:

#pragma comment (lib, "crypt32");
like image 66
jww Avatar answered Sep 21 '22 03:09

jww