[CONC-450] undefined reference to `mysql_init' Created: 2019-12-22  Updated: 2019-12-23  Resolved: 2019-12-23

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Perry Winkel Assignee: Georg Richter
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Ubuntu 18.04



 Description   

I have the most recent package:
sudo apt install mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
mariadb-server is already the newest version (1:10.1.43-0ubuntu0.18.04.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

The following program:

#include <iostream>
#include <mysql.h>
int main(int argc, char *argv[])

{ MYSQL *conn; conn=mysql_init(NULL); mysql_close(conn); return 0; }

when compiled with

g++ -I/usr/include/mariadb -I/usr/include/mariadb/mysql -L/usr/lib/x86_64-linux-gnu/ -lmariadb -lz -ldl -lm -lpthread my.cpp

gives the error:

/tmp/cchC9TlH.o: In function `main':
my.cpp.text+0x15): undefined reference to `mysql_init'
my.cpp.text+0x25): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status



 Comments   
Comment by Georg Richter [ 2019-12-22 ]

Are you sure that you're using MariaDB Connector/C and if yes, how did you install it?
MariaDB Connector/C is bundled together with server since 10.2, but you're using 10.1.

Comment by Perry Winkel [ 2019-12-22 ]

I installed it using:

sudo apt install mariadb-server
sudo apt install mariadb-client
apt install libmariadb-dev

What I got was
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Comment by Georg Richter [ 2019-12-23 ]

Can you please also tell me the output of

$ mariadb_config

Comment by Perry Winkel [ 2019-12-23 ]

btw, thanks for your comments so far the output of mariadb:

za@mbp-2008:~$ mariadb_config --cflags
-I/usr/include/mariadb -I/usr/include/mariadb/mysql
za@mbp-2008:~$ mariadb_config --libs
-L/usr/lib/x86_64-linux-gnu/ -lmariadb -lz -ldl -lm -lpthread -lssl -lcrypto
za@mbp-2008:~$

Comment by Georg Richter [ 2019-12-23 ]

Just tested it with ubuntu packages and it worked as expected after fixing your build command: (compile first, then link):

$ g++ -o mytest my.cpp `mariadb_config --cflags --libs`

or for newer versions of Connector/C

$ g++ -o mytest my.cpp `mariadb_config --cflags --libs --libs_sys`

Comment by Perry Winkel [ 2019-12-23 ]

thanks for for your comment, my configuration gives the following:

za@mbp-2008:~$ g++ -o mytest my.cpp `mariadb_config --cflags --libs`
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
za@mbp-2008:~$ g++ -o mytest my.cpp `mariadb_config --cflags --libs --libs_sys`
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status

Comment by Perry Winkel [ 2019-12-23 ]

I installed the mariadb tarball from https://downloads.mariadb.org/mariadb/10.4.11/

Now I can use mysql_config and everything compiles ok! Again thank you Georg for thinking with me. I very much appreciate that. I hope this thread will be of any assistance to others who face the same troubles. Perry

Generated at Thu Feb 08 03:05:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.