如何使用具有相同外部符号的2个库?

huangapple go评论88阅读模式
英文:

How do I use 2 libraries with same external symbols?

问题

我在我的项目中有两个库 - MySQL C++ Connector 和用于套接字的OpenSSL库,我认为MySQL库已经包含了OpenSSL函数。

我遇到的错误

我遇到的错误(以文本格式):

1>libcrypto.lib(libcrypto-lib-x509_d2.obj):错误LNK2005:X509_STORE_load_locations已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-ct_policy.obj):错误LNK2005:CT_POLICY_EVAL_CTX_free已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-ct_policy.obj):错误LNK2005:CT_POLICY_EVAL_CTX_set1_cert已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-ct_policy.obj):错误LNK2005:CT_POLICY_EVAL_CTX_set1_issuer已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-ct_policy.obj):错误LNK2005:CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-ct_policy.obj):错误LNK2005:CT_POLICY_EVAL_CTX_set_time已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_Calc_A已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_Calc_server_key已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_Verify_A_mod_N已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_Verify_B_mod_N已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_check_known_gN_param已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-srp_lib.obj):错误LNK2005:SRP_get_default_gN已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_INFO_free已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_INFO_get0_CERT已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_INFO_get0_NAME已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_INFO_get_type已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_close已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_eof已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_error已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_load已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义
1>libcrypto.lib(libcrypto-lib-store_lib.obj):错误LNK2005:OSSL_STORE_open已在mysqlcppconn-static.lib(libcrypto-1_1-x64.dll)中定义

我的项目包含目录:

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

链接器输入:

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

英文:

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

答案1

得分: 0

静态库和共享库不能混合使用。

mysqlcppconn-static 已经静态链接了 libssl,再次尝试链接 libssl 不会起作用。

mysqlcppconn-static 旨在用于特定目的的应用程序,这些应用程序仅与 mysql 进行静态链接,因此可以在不包含 mysql 和 openssl 库的情况下分发。

每当涉及多个库时,唯一实际可行的方法是仅与共享库进行链接。

英文:

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.

huangapple
  • 本文由 发表于 2023年1月8日 22:57:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定