0

Estou aprendendo a usar o MySql, mas tive alguns problemas ao compilar um programa, em C, utilizando os recuros do MySql. Segue erros abaixo:

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’

Esses erros apareceram no terminal, do ubuntu, após eu dar o comando para compilar o programa:

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

Para usar o MySql eu instalei o mysql-server e o mysql-client:

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

A instalação correu bem e com sucesso. Para testar eu criei tabelas e inseri elementos, na mesma, usando comandos diretos pelo terminal e não tive problemas, então, tenho certeza q a instalação ocorreu de acordo.

Para poder usar os recursos do mysql em C, eu instalei as libs a partir do seguinte comando:

apt-get install libmysqlclient-dev

Aparentemente essa instalação também ocorreu com sucesso, porém, quando compilo o programa de teste, ocorrem os erros que citei acima. Segue abaixo o programa:

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

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

O primeiro erro indica que o compilador não está encontrando os diretórios do mysql, porém, não sei como fazê-lo incluir os diretórios corretamente.

Como faço para incluir corretamente os diretórios do mysql?

1 Resposta 1

2

Isso é erro de digitação nesta linha:

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

É --libs e não -libs

Veja a diferença digitando certo:

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

E errado:

[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]

No caso, pode notar que todos os erros que estão na sua pergunta são causados pelo help retornado no lugar do caminho esperado.

1
  • Entendi! Consegui compilar, com sua dica. Obrigado pelo esclarecimento.
    – Roger
    6/09/2016 às 12:01

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .