Errors compiling program using MySql resources [closed]

0

I'm learning how to use MySql , but I had some problems compiling a program in C using MySql . Here are the errors below:

gcc: error: Usage:: No such file or directory
gcc: error: [OPTIONS]: No such file or directory
gcc: error: Options:: No such file or directory
gcc: error: [-I/usr/include/mysql: No such file or directory
gcc: error: [-I/usr/include/mysql: No such file or directory
gcc: error: [-L/usr/lib/x86_64-linux-gnu: No such file or directory
gcc: error: [-L/usr/lib/x86_64-linux-gnu: No such file or directory
gcc: error: [/usr/lib/mysql/plugin]: No such file or directory
gcc: error: [/var/run/mysqld/mysqld.sock]: No such file or directory
gcc: error: [0]: No such file or directory
gcc: error: [5.7.13]: No such file or directory
gcc: error: [-L/usr/lib/x86_64-linux-gnu: No such file or directory
gcc: error: VAR: No such file or directory
gcc: error: is: No such file or directory
gcc: error: one: No such file or directory
gcc: error: of:: No such file or directory
gcc: error: pkgincludedir: No such file or directory
gcc: error: [/usr/include/mysql]: No such file or directory
gcc: error: pkglibdir: No such file or directory
gcc: error: [/usr/lib/x86_64-linux-gnu]: No such file or directory
gcc: error: plugindir: No such file or directory
gcc: error: [/usr/lib/mysql/plugin]: No such file or directory
gcc: error: unrecognized command line option ‘--cflags’
gcc: error: unrecognized command line option ‘-fno-omit-frame-pointer]’
gcc: error: unrecognized command line option ‘--cxxflags’
gcc: error: unrecognized command line option ‘-fno-omit-frame-pointer]’
gcc: error: unrecognized command line option ‘--libs’
gcc: error: unrecognized command line option ‘--libs_r’
gcc: error: unrecognized command line option ‘--plugindir’
gcc: error: unrecognized command line option ‘--socket’
gcc: error: unrecognized command line option ‘--port’
gcc: error: unrecognized command line option ‘--libmysqld-libs’
gcc: error: unrecognized command line option ‘--variable=VAR’

These errors appeared in the ubuntu terminal, after I gave the command to compile the program:

~$ gcc teste.c -o teste $(mysql_config -libs)

To use MySql I installed mysql-server and mysql-client:

~$ sudo apt-get install mysql-server mysql-client

The installation went well and successfully. To test I created tables and inserted elements in it, using direct commands through the terminal and I had no problems, so I'm sure the installation occurred accordingly.

In order to use mysql resources in C, I installed libs from the following command:

apt-get install libmysqlclient-dev

Apparently this installation also occurred successfully, but when I compile the test program, the errors I mentioned above occur. Here is the program:

#include "stdio.h"
#include "stdlib.h"
#include <mysql/mysql.h>

void main(void)
{
    MYSQL *hMsql = null;
    mysql_init(hMsql); 
}

The first error indicates that the compiler is not finding the mysql directories, however, I'm not sure how to get it to include the directories correctly.

How do I correctly include the mysql directories ?

    
asked by anonymous 05.09.2016 / 22:53

1 answer

2

This is a typo in this line:

~$ gcc teste.c -o teste $(mysql_config -libs)

It is --libs and not -libs

See the difference typing right:

[user@server ~]$ mysql_config --libs
-rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto

And wrong:

[user@server ~]$ mysql_config -libs
Usage: /usr/lib/mysql/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/include/mysql  -g -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC   -DUNIV_LINUX -DUNIV_LINUX]
        --include        [-I/usr/include/mysql]
        --libs           [-rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto]
        --libs_r         [-rdynamic -L/usr/lib/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto]
        --plugindir      [/usr/lib/mysql/plugin]
        --socket         [/var/lib/mysql/mysql.sock]
        --port           [0]
        --version        [5.1.58]
        --libmysqld-libs [-rdynamic -L/usr/lib/mysql -lmysqld -ldl -lz -lpthread -lcrypt -lnsl -lm -lpthread -lrt -lssl -lcrypto]

In this case, you may notice that all errors that are in your question are caused by the help returned instead of the expected path.

    
05.09.2016 / 22:57