c++mysql

fatal error mysql.h:No such file or directory during compilation


I have the following code

#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 try to compile it using

gcc mysqldb.c -o mysql -I/usr/include/mysql -lmysqlclient 

i get an error saying fatal error mysql.h:No such file or directory. how can i successfully compile and run the code


Solution

  • 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.