I do not know if there is some variation in your operation system. Mine is Arch Linux, and I have installed mariaDB. Within the package, there is a program called 'mysql_config' which can provide the right way of compile your program. By runnig
$ mysql_config --help
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/include/mysql]
--include [-I/usr/include/mysql]
--libs [-L/usr/lib -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl]
--libs_r [-L/usr/lib -lmysqlclient_r -lpthread -lz -lm -lssl -lcrypto -ldl]
--plugindir [/usr/lib/mysql/plugin]
--socket [/run/mysqld/mysqld.sock]
--port [0]
--version [10.0.17]
--libmysqld-libs [-L/usr/lib -lmysqld]
--variable=VAR VAR is one of:
pkgincludedir [/usr/include/mysql]
pkglibdir [/usr/lib]
plugindir [/usr/lib/mysql/plugin]
you can see the control flags of the program. With your program, i used the following:
$gcc main.c -o main $(mysql_config --libs --cflags)
and then, by runnig the the new program 'main'
$./main
MySQL client version: 10.0.17-MariaDB
which clearly worked out!
So, i'm sure that there a few others ways of doing this, but now this is fine for me.
Tip
Run the command
$mysql_config --libs --cflags
to see the exacly flags that mysql_config produces. Enjoy!