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

Zack
  • 117
  • 1
  • 11
  • That means that you need to link also with a libraries, which provide missed symbols: [ssl](https://stackoverflow.com/a/10994403/3440745) and [crypto](https://stackoverflow.com/a/33217370/3440745). – Tsyvarev Jun 10 '19 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 – Zack Jun 10 '19 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)` – Tsyvarev Jun 10 '19 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. – Zack Jun 10 '19 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. – Tsyvarev Jun 10 '19 at 22:23
  • Thanks for your help, compilation goes fine adding dl and pthread. Now I have errors on executing. I am following this https://stackoverflow.com/questions/16605623/where-can-i-get-a-copy-of-the-file-libstdc-so-6-0-15 One of the simbols missing is GLIBCXX_3.4.20, but i found it in my system – Zack Jun 10 '19 at 22:39

1 Answers1

0

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

Zack
  • 117
  • 1
  • 11