2

I'm practicing with the MySQL C API, because I need to do a project for the university. I have a problem after compiling with gcc on ubuntu.

I'm working with MariaDB on simple example like this:

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
   printf("MySQL client version: %s\n", mysql_get_client_info());
   exit(0);
}

When I compile with GCC with this command:

$ gcc version.c -o version  `mysql_config --cflags --libs`

I receive this error that i can't resolve:

/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lssl
collect2: error: ld returned 1 exit status

Can someone help me?

  • 2
    Ensure that the development package providing libssl is installed. I would have expected that to be already done if you installed the mariadb development components from a package, but for whatever reason, they do not appear to be present. See [Install openssl-dev on Ubuntu server](https://serverfault.com/questions/249340/install-openssl-dev-on-ubuntu-server). – John Bollinger Mar 27 '19 at 15:13
  • 1
    What is the actual output from `mysql_config --cflags --libs`? – Andrew Henle Mar 27 '19 at 15:17
  • @AndrewHenle this is the outpu: -I/usr/include/mariadb -I/usr/include/mariadb/mysql -L/usr/lib/x86_64-linux-gnu/ -lmariadb -lz -ldl -lm -lpthread -lssl -lcrypto – Giacomo Intini Mar 27 '19 at 15:22
  • From the looks of it, the system doesn't have OpenSSL installed - at least not in the normal place, and the `-lssl -lcrypto` options try to link in the OpenSSL libraries. What do you get if you enter the `openssl` command on the system? If that works (you get an `OpenSSL>` prompt that you have to enter `exit` to quit), what the full path of the `openssl` executable and what's the output from `ldd /full/path/to/openssl`? Because the `openssl` binary itself should depend on the same libraries. And if MariaDB is installed, OpenSSL should be installed too. – Andrew Henle Mar 27 '19 at 15:29
  • @AndrewHenle OpenSSL works. The full path is `/usr/bin/openssl `. The output for the `ldd` command is `linux-vdso.so.1 (0x00007fffd0b70000) libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fac6c4be000) libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fac6c046000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fac6be27000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fac6ba36000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fac6b832000) /lib64/ld-linux-x86-64.so.2 (0x00007fac6c9c9000) ` – Giacomo Intini Mar 27 '19 at 15:38
  • @GiacomoIntini Did you installed `libmariadbclient-dev` and then `libmariadb-dev-compat`? If yes, then do again: `sudo apt-get install libmariadbclient-dev libssl-dev` and see if are still there. – Michi Mar 27 '19 at 15:47
  • @GiacomoIntini Also, what says `LDD` here: `ld -lssl --verbose | grep "attempt"` ? – Michi Mar 27 '19 at 16:05
  • Which repository was mariadb installed from? Please show the output of `apt-cache policy libmariadbclient-dev`. – Ian Abbott Mar 27 '19 at 17:09
  • @Michi thanks for helping, the output of `sudo apt-get install libmariadbclient-dev libssl-dev` is `The following packages have unmet dependencies: libmariadbclient-dev : Depends: libmariadbclient18 (= 1:10.1.38-0ubuntu0.18.04.1) but 1:10.3.13+maria~bionic is to be installed E: Unable to correct problems, you have held broken packages.` – Giacomo Intini Mar 27 '19 at 19:01
  • @Michi instead about the second command you adviced me the output is : `ld: cannot find -lssl` and failed attempt to open – Giacomo Intini Mar 27 '19 at 19:02
  • @IanAbbott thank for helping, the output is: `libmariadbclient-dev: Installed: (none) Candidate: 1:10.1.38-0ubuntu0.18.04.1 Version table: 1:10.1.38-0ubuntu0.18.04.1 500 500 http://it.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages 500 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages 1:10.1.29-6 500 500 http://it.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages 10.1.38+maria-1~xenial 500 500 http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu xenial/main amd64 Packages ` – Giacomo Intini Mar 27 '19 at 19:03
  • @GiacomoIntini I think we can deduce from the output that you have installed MariaDB from (a mirror of) MariaDB's own package repositories, rather than from Ubuntu's repositories. That explains why I was unable to reproduce your problem. – Ian Abbott Mar 28 '19 at 10:36
  • @IanAbbott so do you have any solution for my problem? – Giacomo Intini Mar 28 '19 at 11:40
  • I think the problem is you have some mariadb packages installed from the Ubuntu main repository and some installed from the 3rd party MariaDB repository, so the package dependencies have got into a bit of a mess. – Ian Abbott Mar 28 '19 at 13:02
  • @IanAbbott the problem was that I could't install MariaDB with the simple command, `sudo apt-get install ibmariadbclient-dev libssl-dev`. And now I don't know how to solve the problem – Giacomo Intini Mar 29 '19 at 11:12
  • You'll need to undo the mess somehow, perhaps by attempting to fix the broken packages with `apt-get install -f`. It that doesn't work, you'll need to use a terminal GUI-based package management tool such as "aptitude", or a desktop GUI-based tool such as "Synaptic Package Manager" to try and clean things up. – Ian Abbott Mar 29 '19 at 15:28

0 Answers0