0

I installed ubuntu on a virtual machine.There,I installed mysql server(sudo apt-get install mysql-server) .This worked, because I could acces mysql-u root -p password. After that,I did : sudo apt-get install libmysqlclient-dev.

#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 this with gcc version.c -o version mysql_config --cflags --libs it works. But when I compile this one from below( gcc createdb.c -o createdb -std=c99 mysql_config --cflags --libs) I get some errors.

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

int main(int argc, char **argv)
{  
  MYSQL *con = mysql_init(NULL);

  if (con == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      exit(1);
  }

  if (mysql_real_connect(con, "localhost", "root", "root_pswd", 
          NULL, 0, NULL, 0) == NULL) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }  

  if (mysql_query(con, "CREATE DATABASE testdb")) 
  {
      fprintf(stderr, "%s\n", mysql_error(con));
      mysql_close(con);
      exit(1);
  }

  mysql_close(con);
  exit(0);
}

Errors:

"Usage:: No such file or directory
[OPTIONS]: No such file or directory
Options:: No such file or directory
[-I/usr/include/mysql: No such file or directory
[-L/user/lib/x86_64-linux-gnu: No such file or directory
.
.
.
unrecognized command line option '--cflags'
unrecognized command line option '--libs'
.
.
unrecognized command line option '--socket'
unrecognized command line option '--port' "

Can someone explain me what I did wrong,and how to fix it? I just want to get some data from tables in a C program.

closed as off-topic by Seth Dec 22 '14 at 0:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

You need command substitution syntax around the mysql_config command; either with 'backticks':

gcc createdb.c -o createdb -std=c99 `mysql_config --cflags --libs`

or with $(...)

gcc createdb.c -o createdb -std=c99 $(mysql_config --cflags --libs)
  • This question was also posted by the same user in SO, and there are responses. Using mysql in c programming – Paul Dec 21 '14 at 23:37
  • I had that commnad substitution syntax around the mysql_config. Also tried $(mysql_....) ,but I get the same errors... – unt mazga Dec 22 '14 at 6:42
  • @untmazga I've tried with your example code and this all works. The errors suggest you're stuffing something incorrect into the shell. – Oli Dec 22 '14 at 11:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.