The issue of errors when referencing the client-cpp static library of TiKV in the project

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 项目里引用tikv的client-cpp客户端静态库 最后报错的问题

| username: TiDBer_CozPRH8J

To improve efficiency, please provide the following information. A clear problem description can help resolve the issue faster:

[Overview] A cpp project integrates TiKV, using the client-cpp compiled static library, and encounters compilation errors when introduced into the project.

[Application Framework and Business Logic Adaptation]

[Background] The static library was compiled directly using the code from https://github.com/tikv/client-cpp.

[Problem] The compiled libkv_client.a library is used in the project and includes the corresponding header files. Compilation errors occur during the final linking stage of the project. The error messages indicate conflicts between the SSL of the static library and the project’s SSL. How can this be resolved? The libraries are compiled with default settings without any modifications.

[Business Impact]

[TiDB Version]

[Attachments] Error messages are as follows:
Make Error: Parse error in command line argument: TIKV
Should be: VAR:type=value

CMake Error: Run ‘cmake --help’ for all supported options.
make[1]: warning: -jN forced in submake: disabling jobserver mode.
CMakeFiles/bif_ca.dir/main.cpp.o: In function asio::ssl::detail::openssl_init_base::do_init::~do_init()': /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:73: undefined reference to CONF_modules_unload’
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:75: undefined reference to ENGINE_cleanup' CMakeFiles/bif_ca.dir/main.cpp.o: In function asio::ssl::detail::openssl_init_base::do_init::~do_init()‘:
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:73: undefined reference to CONF_modules_unload' /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:75: undefined reference to ENGINE_cleanup’
CMakeFiles/bif_ca.dir/main.cpp.o: In function asio::ssl::detail::openssl_init_base::do_init::do_init()': /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:40: undefined reference to OPENSSL_add_all_algorithms_noconf’
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:40: undefined reference to OPENSSL_add_all_algorithms_noconf' /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:40: undefined reference to OPENSSL_add_all_algorithms_noconf’
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:40: undefined reference to OPENSSL_add_all_algorithms_noconf' /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/openssl_init.ipp:40: undefined reference to OPENSSL_add_all_algorithms_noconf’
/home/liuyuanchao/BIF-Core/lib/libbifchain_common.a(ca.cpp.o):/home/liuyuanchao/BIF-Core/src/common/ca.cpp:137: more undefined references to OPENSSL_add_all_algorithms_noconf' follow /home/liuyuanchao/BIF-Core/lib/libbifchain_common.a(ca.cpp.o): In function bifchain::CA::Add_ExtCert(x509_st*, x509_st*, int, char const*)‘:
/home/liuyuanchao/BIF-Core/src/common/ca.cpp:227: undefined reference to X509V3_EXT_conf_nid' /home/liuyuanchao/BIF-Core/lib/libbifchain_common.a(ca.cpp.o): In function bifchain::CA::Add_ExtReq(stack_st_X509_EXTENSION*, int, char*)’:
/home/liuyuanchao/BIF-Core/src/common/ca.cpp:277: undefined reference to X509V3_EXT_conf_nid' /home/liuyuanchao/BIF-Core/lib/libbifchain_common.a(ca.cpp.o): In function bifchain::CA::mkReq(bifchain::stuSUBJECT*, X509_req_st**, rsa_st**, evp_pkey_st**, int, char*)‘:
/home/liuyuanchao/BIF-Core/src/common/ca.cpp:302: undefined reference to RSA_generate_key' /home/liuyuanchao/BIF-Core/lib/libbifchain_common.a(ca.cpp.o): In function bifchain::CA::mkRoot(bifchain::stuSUBJECT*, x509_st**, rsa_st**, evp_pkey_st**, int, int, char*)’:
/home/liuyuanchao/BIF-Core/src/common/ca.cpp:1288: undefined reference to RSA_generate_key' /home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(net.cpp.o): In function asio::ssl::detail::engine::engine(ssl_ctx_st*)‘:
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/engine.ipp:49: undefined reference to SSL_ctrl' /home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/engine.ipp:50: undefined reference to SSL_ctrl’
/home/liuyuanchao/BIF-Core/src/3rd/asio/include/asio/ssl/detail/impl/engine.ipp:52: undefined reference to SSL_ctrl' /home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::GetCFCAGroup()‘:
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:83: undefined reference to EC_GROUP_new' /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:84: undefined reference to EC_GROUP_set_curve_GFp’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::NewRandom()': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:377: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::NewGroup(utils::EccSm2::GROUP_TYPE, std::string, std::string, std::string, std::string, std::string, std::string)': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:212: undefined reference to EC_GF2m_simple_method’
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:212: undefined reference to EC_GROUP_new' /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:217: undefined reference to EC_GROUP_set_curve_GF2m’
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:222: undefined reference to EC_POINT_set_affine_coordinates_GF2m' /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:230: undefined reference to EC_GROUP_check’
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:155: undefined reference to EC_GROUP_new' /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:160: undefined reference to EC_GROUP_set_curve_GFp’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::GetPublicKey()': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:699: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::getZA(ec_group_st*, std::string, ec_point_st const*)': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:256: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:265: undefined reference to EC_POINT_get_affine_coordinates_GF2m' /home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::verify(ec_group_st*, std::string const&, std::string const&, std::string const&, std::string const&)‘:
/home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:587: undefined reference to EC_POINT_set_affine_coordinates_GF2m' /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:644: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::From(std::string)': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:335: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
/home/liuyuanchao/BIF-Core/lib/libbifchain_utils.a(ecc_sm2.cpp.o): In function utils::EccSm2::Sign(std::string const&, std::string const&)': /home/liuyuanchao/BIF-Core/src/utils/ecc_sm2.cpp:474: undefined reference to EC_POINT_get_affine_coordinates_GF2m’
collect2: error: ld returned 1 exit status
make[3]: *** [/home/liuyuanchao/BIF-Core/bin/bif_ca] Error 1
make[2]: *** [ca/CMakeFiles/bif_ca.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs…
/home/liuyuanchao/BIF-Core/src/3rd/tikv/libtikv_client.a(d1_both.cc.o): In function bssl::hm_fragment::~hm_fragment()': d1_both.cc:(.text._ZN4bssl11hm_fragmentD2Ev+0x0): multiple definition of bssl::hm_fragment::~hm_fragment()’
/home/liuyuanchao/BIF-Core/src/3rd/openssl/libssl.a(d1_both.cc.o):d1_both.cc:(.text+0x74): first defined here
/home/liuyuanchao/BIF-Core/src/3rd/tikv/libtikv_client.a(d1_both.cc.o): In function bssl::hm_fragment::~hm_fragment()': d1_both.cc:(.text._ZN4bssl11hm_fragmentD2Ev+0x0): multiple definition of bssl::hm_fragment::~hm_fragment()’
/home/liuyuanchao/BIF-Core/src/3rd/openssl/libssl.a(d1_both.cc.o):d1_both.cc:(.text+0x74): first defined here
/home/liuyuanchao/BIF-Core/src/3rd/tikv/libtikv_client.a(d1_both.cc.o): In function bssl::dtls1_get_message(ssl_st const*, bssl::SSLMessage*)': d1_both.cc:(.text._ZN4bssl17dtls1_get_messageEPK6ssl_stPNS_10SSLMessageE+0x0): multiple definition of bssl::dtls1_get_message(ssl_st const*, bssl::SSLMessage*)’
/home/liuyuanchao/BIF-Core/src/3rd/openssl/libssl.a(d1_both.cc.o):d1_both.cc:(.text+0xeb3): first defined here
/home/liuyuanchao/BIF-Core/src/3rd/tikv/libtikv_client.a(d1_both.cc.o): In function bssl::dtls1_next_message(ssl_st*)': d1_both.cc:(.text._ZN4bssl18dtls1_next_messageEP6ssl_st+0x0): multiple definition of bssl::dtls1_next_message(ssl_st*)’


For performance optimization or troubleshooting questions, please download and run the script. Be sure to select all terminal output and copy-paste it for upload.

| username: yilong | Original post link

If libkv_client.a is edited, it feels like tikv client-cpp is already completed.