1

I am writing about a problem I had during the setup of MySQL Connector C++. I am using the binary distribution of the connector for Linux (Ubuntu 18.04), so I put the library directory outside my project (that is one of the examples given in the reference guide here (https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-installation-binary.html).

In my project (Clion) I have this cmake file:

cmake_minimum_required(VERSION 3.14)
project(MySQLConnectorTest)

set(CMAKE_CXX_STANDARD 14)

link_directories(../mysql-connector-c++/lib64)
link_directories(/opt/lampp/lib)
add_executable(MySQLConnectorTest main.cpp)
include_directories(../mysql-connector-c++/include/jdbc)
target_link_libraries(MySQLConnectorTest mysqlclient.a)
target_link_libraries(MySQLConnectorTest mysqlcppconn-static.a)

The mySQL istallation I have is the one provided with XAMPP. So the directory where to find mysqlclient.a is /opt/lampp/lib

The problem is when linking mysqlcppconn-static.a, during compilation I obtain a long list of errors like the following:

/home/riccardo/MySQLConnectorTest/../mysql-connector-c++/lib64/libmysqlcppconn-static.a(libmysqlclient_client.cc.o): 
nella funzione "ssl_verify_server_cert(Vio*, char const*, char const**) [clone .isra.7]":
./obj/libmysql/../../mysql-8.0.16/sql-common/client.cc:3283: riferimento non definito a "SSL_get_peer_certificate"
./obj/libmysql/../../mysql-8.0.16/sql-common/client.cc:3288: riferimento non definito a "SSL_get_verify_result"
./obj/libmysql/../../mysql-8.0.16/sql-common/client.cc:3359: riferimento non definito a "X509_free"
./obj/libmysql/../../mysql-8.0.16/sql-common/client.cc:3302: riferimento non definito a "X509_check_host"
./obj/libmysql/../../mysql-8.0.16/sql-common/client.cc:3304: riferimento non definito a "X509_check_ip_asc"

Can someone explain me what does this mean? Can someone suggest me how to fix?

Thanks in advance.

[EDIT]: following the suggestion provided here, the compilation now goes fine. I think there is still one problem, the example program throws an exception when calling the connect method:

/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");

I've found other posts regarding this issue, like c++ mysql connection bad_alloc using c++ connector but this doesn't help in linux, in particular i tried to follow the hint:

I had the same error on linux. The error was : I was using g++-4.8 to build the project The issue lies on the version of the build tools (gcc,msvs,clang) used to build the project by trying to update g++, but I have tha latest version. Probably is more difficult to make this library work than writing the code I need for my application, I hope someone can suggest me what to try next.

Thanks

6
  • That means that you need to link also with a libraries, which provide missed symbols: ssl and crypto. Commented Jun 10, 2019 at 19:46
  • Thanks for the comment, tried to add the following lines: target_link_libraries(MySQLConnectorTest ssl.so) target_link_libraries(MySQLConnectorTest crypto.so) But nothing changes in the output Commented Jun 10, 2019 at 21:44
  • As it is mysqlcppconn-static.a library which requires missed symbols, ssl and crypto libraries should be added after it: target_link_libraries(MySQLConnectorTest mysqlcppconn-static.a ssl crypto) Commented Jun 10, 2019 at 21:55
  • Oh ok, this seems to start working but now i have this error: /usr/bin/ld: /home/riccardo/MySQLConnectorTest/../mysql-connector-c++/lib64/libmysqlcppconn-static.a(libmysqlclient_client_plugin.cc.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line Trying to add "dl" to the end, but this makes a lot of errors for pthread. Commented Jun 10, 2019 at 22:21
  • So you need to link with dl library too. Just google for the missed symbols and you will find which library you need to link with. Commented Jun 10, 2019 at 22:23

1 Answer 1

1

Seems I solved in a simple manner. I write here what I tried and what errors I got. I read again the develper guide and seems that using the binaries provided there could be problems because of the different compilers used for the library and for the project. I tried then to compile the sources to assure that the compiler used for the library and for my project is the same. I followed this guide: https://aaronxu17.github.io/blog/install-mysql-connector/

This didn't work, the library compiled was named mysqlcppconn8-static.a instead of mysqlcppconn-static.a, but changing the name reference to that one I have had a compilation error like this:

reference not defined to get_driver_instance

Finally I found this https://stackoverrun.com/it/q/4344116, and solved simply with

sudo apt-get install libmysqlcppconn-dev

Now all of what tried seems stupid against the final solution. I hope this can save time to other people. Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.