Home > Enterprise >  How do I use 2 libraries with same external symbols?
How do I use 2 libraries with same external symbols?

Time:01-09

I have 2 libraries in my project - MySQL C Connector and OpenSSL library for sockets, and as I think MySQL library already has OpenSSL functions inside.

Errors I get

Errors I get (in text format):

1>libcrypto.lib(libcrypto-lib-x509_d2.obj) : error LNK2005: X509_STORE_load_locations already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_free already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set1_cert already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set1_issuer already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-ct_policy.obj) : error LNK2005: CT_POLICY_EVAL_CTX_set_time already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Calc_A already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Calc_server_key already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Verify_A_mod_N already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_Verify_B_mod_N already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_check_known_gN_param already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-srp_lib.obj) : error LNK2005: SRP_get_default_gN already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_free already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get0_CERT already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get0_NAME already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_INFO_get_type already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_close already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_eof already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_error already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_load already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)
1>libcrypto.lib(libcrypto-lib-store_lib.obj) : error LNK2005: OSSL_STORE_open already defined in mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)

My project include directories:

\asio-1.24.0\include
\openssl\Lib\x64\Release\include
\MySQL\Connector C   8.0\include\jdbc

Linker input:

\openssl\Lib\x64\Release\lib\libcrypto.lib
\openssl\Lib\x64\Release\lib\libssl.lib
crypt32.lib
mysqlcppconn-static.lib

CodePudding user response:

Static and shared libraries cannot be mixed like that.

mysqlcppconn-static is statically linked with libssl, and attempting to link, again, with libssl is not going to work.

mysqlcppconn-static is meant to be used with special-purpose applications that get statically linked only with mysql, and so they can be distributed without the mysql and openssl libraries.

Whenever multiple libraries are involved the only practical approach is to link only with shared libraries.

  • Related