oatpp / oatpp-openssl

OpenSSL adaptor for Oat++ applications
https://oatpp.io/
Apache License 2.0
13 stars 22 forks source link

Static Linking Against OpenSSL on Windows x86 #15

Open mojomojomojo opened 2 years ago

mojomojomojo commented 2 years ago

I'm trying to build oatpp-openssl out of the box, statically linking against OpenSSL (1.1.1j).

git clone https://github.com/oatpp/oatpp-openssl.git
mkdir oatpp-openssl\build & cd oatpp-openssl\build
cmake .. -G "Visual Studio 15 2017" "-DCMAKE_PREFIX_PATH=c:\PATH\TO\OATPP_RUNTIME" "-DOPENSSL_ROOT_DIR=C:\PATH\TO\OPENSSL\openssl\static"
cmake --build . --config RelWithDebInfo

The build goes as expected until link time.

"C:\TEST_BUILD_DIR\oatpp-openssl\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj" (default target) (3) ->
(Link target) -> 
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertOpenStore@20 referenced in function _capi_open_store [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertCloseStore@8 referenced in function _capi_find_key [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertEnumCertificatesInStore@8 referenced in function _capi_find_cert [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFindCertificateInStore@24 referenced in function _capi_find_cert [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertDuplicateCertificateContext@4 referenced in function _capi_load_ssl_client_cert [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertFreeCertificateContext@4 referenced in function _capi_dsa_free [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  libcrypto.lib(e_capi.obj) : error LNK2019: unresolved external symbol __imp__CertGetCertificateContextProperty@16 referenced in function _capi_cert_get_fname [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]
  C:\TEST_BUILD_DIR\oatpp-openssl\build\test\RelWithDebInfo\module-tests.exe : fatal error LNK1120: 7 unresolved externals [C:\TEST_BUILD_DIR\oatpp-openssl\build\test\module-tests.vcxproj]

These functions are defined (in Windows) in Crypt32.lib.

I can fix this issue on my system by

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index aa10867..ca373ce 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -38,6 +38,7 @@ target_include_directories(${OATPP_THIS_MODULE_NAME}
 target_link_libraries(${OATPP_THIS_MODULE_NAME}
         PUBLIC OpenSSL::SSL
         PUBLIC OpenSSL::Crypto
+        Crypt32
 )

 #######################################################################################################

However, I doubt that this is the correct solution, because it is likely only needed