Errors when compiling program using Mysql resources

Asked

Viewed 127 times

0

I’m learning to use the Mysql, but I had some problems compiling a program, in C, using the resources of Mysql. Follows 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 the same, using direct commands from the terminal and had no problems, then, I am sure q the installation occurred accordingly.

In order to use the resources of mysql in C, I installed the 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. Below 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 directories of the mysql, however, I don’t know how to make it include the directories correctly.

How do I correctly include the directories of mysql?

1 answer

2


That’s typo on this line:

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

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 case, you may notice that all errors that are in your question are caused by help returned at the place of the expected path.

  • Got it! I was able to compile, with your tip. Thanks for the clarification.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.