I have the following code
#include
#include
int main(int argc, char **argv)
{
printf(\"MySQL client version: %s\\n\",
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.
Run the command
$mysql_config --libs --cflags
to see the exacly flags that mysql_config produces. Enjoy!
Check that /usr/include/mysql/mysql.h
exists. If you have installed the header files somewhere else (say /opt/mysql/include
), add that location with -I/opt/mysql/include.
I come across the same error today, turn out that I forget to install package libmysqlclient-dev
. After I install it with
sudo apt install libmysqlclient-dev
the error went away.
I had the same problem, but fortunately the command
sudo apt install libmysqlclient-dev
as specified by
user4713908 fixed it.
I juat had to specify the path in my makefile as
gcc -o database1 chapter5_1.c -I/usr/include/mysql
I'm using Kali Linux