Erro compilar exemplos mysql++ com g++

1. Erro compilar exemplos mysql++ com g++

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 30/04/2008 - 16:52h

Resolvi estudar acesso ao mysql com c++ e estou tendo problemas com a biblioteca mysql++. Ao testar os exemplos que veem junto, estou com o seguinte erro:

debian:/home/paulo/examples# g++ -I/usr/include/mysql -I/usr/include/mysql++ -o simple simple1.cpp
printdata.h:35: error: expected unqualified-id before ‘&’ token
printdata.h:35: error: expected ‘,’ or ‘...’ before ‘&’ token
printdata.h:37: error: ISO C++ forbids declaration of ‘parameter’ with no type
printdata.h:38: error: variable or field ‘print_stock_rows’ declared void
printdata.h:38: error: ‘StoreQueryResult’ is not a member of ‘mysqlpp’
printdata.h:38: error: ‘res’ was not declared in this scope
simple1.cpp: In function ‘int main(int, char**)’:
simple1.cpp:52: error: no matching function for call to ‘mysqlpp::Connection::query(const char [23])’
/usr/include/mysql++/connection.h:199: note: candidates are: mysqlpp::Query mysqlpp::Connection::query()
simple1.cpp:53: error: ‘StoreQueryResult’ is not a member of ‘mysqlpp’
simple1.cpp:53: error: expected `)' before ‘res’
simple1.cpp:55: error: ‘res’ was not declared in this scope

Instalei o mysql++ via apt-get:
libmysql++-dev
libmysql++3
libmysqlclient15-dev

tenho a pasta mysql++ em /usr/local/includes/mysql++

alguem sabe o que estou fazendo de errado?


  


2. Re: Erro compilar exemplos mysql++ com g++

Rodrigo Ferreira Valentim
engos

(usa openSUSE)

Enviado em 12/05/2008 - 14:50h

O problema aparentemente está na codificação em si do seu programa, na forma como você está utilizando a biblioteca, não na instalação da biblioteca em si.

Disponibilize o código completo para podermos compilar e analisar.

[]s


3. Re: Erro compilar exemplos mysql++ com g++

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 12/05/2008 - 15:32h

eaí Engos
o arquivo que estou tentando compilar é o de exemplo que veem junto com o pacote mysql++:


#include "cmdline.h"
#include "printdata.h"
#include <mysql++.h>
#include <iostream>
#include <iomanip>

using namespace std;

int
main(int argc, char *argv[])
{
// Get database access parameters from command line
const char* db = 0, *server = 0, *user = 0, *pass = "";
if (!parse_command_line(argc, argv, &db, &server, &user, &pass)) {
return 1;
}

// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
for (size_t i = 0; i < res.num_rows(); ++i) {
cout << '\t' << res[i][0] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return 1;
}

return 0;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return 1;
}
}





já tenho a base de dados criada e tudo mais, se bem que isso não tem nada a ver com o erro que está dando... caso puder ajudar agradeço



4. ta faltando linkar

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 12/05/2008 - 15:43h

g++ -lmysqlpp -I/usr/include/mysql++ $(mysql_config --libs) $(mysql_config --cflags) -o simple simple1.cpp

Nos exemplos que vi não precisou do:
-I/usr/include/mysql
Acho que isso somente para C



5. Re: Erro compilar exemplos mysql++ com g++

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 12/05/2008 - 16:01h

ok, fiz exatamente como você mostrou :
g++ -lmysqlpp -I/usr/include/mysql++ $(mysql_config --libs) $(mysql_config --cflags) -o simple simple1.cpp


mais está retornando os erros:
printdata.h:35: error: expected unqualified-id before '&' token
printdata.h:35: error: expected ',' or '...' before '&' token
printdata.h:37: error: ISO C++ forbids declaration of 'parameter' with no type
printdata.h:38: error: variable or field 'print_stock_rows' declared void
printdata.h:38: error: 'StoreQueryResult' is not a member of 'mysqlpp'
printdata.h:38: error: 'res' was not declared in this scope
simple1.cpp: In function 'int main(int, char**)':
simple1.cpp:52: error: no matching function for call to 'mysqlpp::Connection::query(const char [23])'
/usr/include/mysql++/connection.h:199: note: candidates are: mysqlpp::Query mysqlpp::Connection::query()
simple1.cpp:53: error: 'StoreQueryResult' is not a member of 'mysqlpp'
simple1.cpp:53: error: expected `)' before 'res'
simple1.cpp:55: error: 'res' was not declared in this scope



estranho não?


6. cara

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 12/05/2008 - 16:22h

tenta trocar mysql_config
por:
/usr/local/mysql/mysql_config
ou onde estiver seu mysql_config.
O mysql ta funfando bonitinho?



7. ta complicado...

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 12/05/2008 - 16:32h

fiz como vc disse:
g++ -lmysqlpp -I/usr/include/mysql++ $(/usr/bin/mysql_config --libs) $(/usb/bin/mysql_config --cflags) -o simple simple1.cpp

meu mysql_config se encontra em /usr/bin/
e o mysql está funcionando 100%


mais olha o erro que dá agora:
server:/home/web/www/arqs/mysql++-3.0.2/examples# g++ -lmysqlpp -I/usr/include/mysql++ $(/usr/bin/mysql_config --libs) $(/usb/bin/mysql_config --cflags) -o simple simple1.cpp
-bash: /usb/bin/mysql_config: No such file or directory
In file included from /usr/include/mysql++/connection.h:40,
from /usr/include/mysql++/mysql++.h:54,
from printdata.h:31,
from simple1.cpp:29:
/usr/include/mysql++/defs.h:34:19: error: mysql.h: No such file or directory
/usr/include/mysql++/defs.h:66: error: 'MYSQL_FIELD' does not name a type
/usr/include/mysql++/connection.h:142: error: 'my_bool' has not been declared
/usr/include/mysql++/connection.h:159: error: 'my_bool' has not been declared
/usr/include/mysql++/connection.h:355: error: 'st_mysql_options' does not name a type
/usr/include/mysql++/connection.h:422: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/connection.h:433: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/connection.h:483: error: 'mysql_option' has not been declared
/usr/include/mysql++/connection.h:540: error: 'MYSQL' does not name a type
/usr/include/mysql++/connection.h: In member function 'void mysqlpp::Connection::close()':
/usr/include/mysql++/connection.h:167: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:167: error: 'mysql_close' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'const char* mysqlpp::Connection::error()':
/usr/include/mysql++/connection.h:224: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:224: error: 'mysql_error' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'int mysqlpp::Connection::errnum()':
/usr/include/mysql++/connection.h:231: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:231: error: 'mysql_errno' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'int mysqlpp::Connection::refresh(unsigned int)':
/usr/include/mysql++/connection.h:243: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:243: error: 'mysql_refresh' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'int mysqlpp::Connection::ping()':
/usr/include/mysql++/connection.h:256: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:256: error: 'mysql_ping' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'int mysqlpp::Connection::kill(long unsigned int)':
/usr/include/mysql++/connection.h:265: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:265: error: 'mysql_kill' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'std::string mysqlpp::Connection::client_info()':
/usr/include/mysql++/connection.h:273: error: 'mysql_get_client_info' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'std::string mysqlpp::Connection::host_info()':
/usr/include/mysql++/connection.h:284: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:284: error: 'mysql_get_host_info' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'int mysqlpp::Connection::proto_info()':
/usr/include/mysql++/connection.h:293: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:293: error: 'mysql_get_proto_info' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'std::string mysqlpp::Connection::server_info()':
/usr/include/mysql++/connection.h:301: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:301: error: 'mysql_get_server_info' was not declared in this scope
/usr/include/mysql++/connection.h: In member function 'std::string mysqlpp::Connection::stat()':
/usr/include/mysql++/connection.h:312: error: 'mysql_' was not declared in this scope
/usr/include/mysql++/connection.h:312: error: 'mysql_stat' was not declared in this scope
/usr/include/mysql++/fields.h: At global scope:
/usr/include/mysql++/fields.h:41: error: 'Field' was not declared in this scope
/usr/include/mysql++/fields.h:41: error: template argument 2 is invalid
/usr/include/mysql++/fields.h:41: error: template argument 3 is invalid
/usr/include/mysql++/fields.h:54: error: ISO C++ forbids declaration of 'Field' with no type
/usr/include/mysql++/fields.h:54: error: expected ';' before '&' token
/usr/include/mysql++/fields.h:57: error: ISO C++ forbids declaration of 'Field' with no type
/usr/include/mysql++/fields.h:57: error: expected ';' before '&' token
/usr/include/mysql++/fields.h:62: error: expected `;' before 'size_type'
/usr/include/mysql++/fields.h:62: error: 'size_type' does not name a type
/usr/include/mysql++/type_info.h:142: error: expected `)' before 't'
/usr/include/mysql++/type_info.h:148: error: expected ',' or '...' before '&' token
/usr/include/mysql++/type_info.h:148: error: ISO C++ forbids declaration of 'MYSQL_FIELD' with no type
/usr/include/mysql++/type_info.h:299: error: 'enum_field_types' has not been declared
/usr/include/mysql++/type_info.h:340: error: expected `)' before 't'
/usr/include/mysql++/type_info.h:346: error: expected ',' or '...' before '&' token
/usr/include/mysql++/type_info.h:346: error: ISO C++ forbids declaration of 'MYSQL_FIELD' with no type
/usr/include/mysql++/type_info.h: In constructor 'mysqlpp::mysql_type_info::mysql_type_info(int)':
/usr/include/mysql++/type_info.h:348: error: 'f' was not declared in this scope
/usr/include/mysql++/type_info.h:348: error: 'UNSIGNED_FLAG' was not declared in this scope
/usr/include/mysql++/type_info.h:349: error: 'NOT_NULL_FLAG' was not declared in this scope
/usr/include/mysql++/row.h: At global scope:
/usr/include/mysql++/row.h:66: error: expected ',' or '...' before '&' token
/usr/include/mysql++/row.h:67: error: ISO C++ forbids declaration of 'MYSQL_ROW' with no type
/usr/include/mysql++/result.h:77: error: expected `)' before '*' token
/usr/include/mysql++/result.h:94: error: ISO C++ forbids declaration of 'MYSQL_RES' with no type
/usr/include/mysql++/result.h:94: error: expected ';' before '*' token
/usr/include/mysql++/result.h:103: error: expected `;' before 'Row'
/usr/include/mysql++/result.h:133: error: ISO C++ forbids declaration of 'Field' with no type
/usr/include/mysql++/result.h:133: error: expected ';' before '&' token
/usr/include/mysql++/result.h:139: error: expected `;' before 'void'
/usr/include/mysql++/result.h:295: error: ISO C++ forbids declaration of 'Field' with no type
/usr/include/mysql++/result.h:295: error: expected ';' before '&' token
/usr/include/mysql++/result.h:305: error: expected `;' before 'bool'
/usr/include/mysql++/result.h:319: error: ISO C++ forbids declaration of 'MYSQL_RES' with no type
/usr/include/mysql++/result.h:319: error: expected ';' before '*' token
/usr/include/mysql++/result.h: In constructor 'mysqlpp::ResUse::ResUse()':
/usr/include/mysql++/result.h:68: error: class 'mysqlpp::ResUse' does not have any field named 'result_'
/usr/include/mysql++/result.h: In member function 'mysqlpp::Row mysqlpp::ResUse::fetch_row()':
/usr/include/mysql++/result.h:105: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:113: error: 'MYSQL_ROW' was not declared in this scope
/usr/include/mysql++/result.h:113: error: expected `;' before 'row'
/usr/include/mysql++/result.h:114: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:114: error: 'mysql_fetch_lengths' was not declared in this scope
/usr/include/mysql++/result.h:115: error: 'row' was not declared in this scope
/usr/include/mysql++/result.h:123: error: 'row' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'long unsigned int* mysqlpp::ResUse::fetch_lengths() const':
/usr/include/mysql++/result.h:129: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:129: error: 'mysql_fetch_lengths' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'void mysqlpp::ResUse::field_seek(int)':
/usr/include/mysql++/result.h:141: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:141: error: 'mysql_field_seek' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'int mysqlpp::ResUse::num_fields() const':
/usr/include/mysql++/result.h:147: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:147: error: 'mysql_num_fields' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'void mysqlpp::ResUse::purge()':
/usr/include/mysql++/result.h:163: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:164: error: 'mysql_free_result' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'mysqlpp::ResUse::operator bool() const':
/usr/include/mysql++/result.h:192: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'bool mysqlpp::ResUse::operator==(const mysqlpp::ResUse&) const':
/usr/include/mysql++/result.h:307: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:307: error: 'const class mysqlpp::ResUse' has no member named 'result_'
/usr/include/mysql++/result.h: In member function 'bool mysqlpp::ResUse::operator!=(const mysqlpp::ResUse&) const':
/usr/include/mysql++/result.h:314: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:314: error: 'const class mysqlpp::ResUse' has no member named 'result_'
/usr/include/mysql++/result.h: At global scope:
/usr/include/mysql++/result.h:355: error: expected `)' before '*' token
/usr/include/mysql++/result.h:400: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/result.h: In member function 'const mysqlpp::Row mysqlpp::Result::fetch_row() const':
/usr/include/mysql++/result.h:378: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:386: error: 'MYSQL_ROW' was not declared in this scope
/usr/include/mysql++/result.h:386: error: expected `;' before 'row'
/usr/include/mysql++/result.h:387: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:387: error: 'mysql_fetch_lengths' was not declared in this scope
/usr/include/mysql++/result.h:388: error: 'row' was not declared in this scope
/usr/include/mysql++/result.h:396: error: 'row' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'void mysqlpp::Result::data_seek(mysqlpp::uint) const':
/usr/include/mysql++/result.h:411: error: 'result_' was not declared in this scope
/usr/include/mysql++/result.h:411: error: 'mysql_data_seek' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'virtual unsigned int mysqlpp::Result::size() const':
/usr/include/mysql++/result.h:417: error: 'num_rows' was not declared in this scope
/usr/include/mysql++/result.h: In member function 'unsigned int mysqlpp::Result::rows() const':
/usr/include/mysql++/result.h:423: error: 'num_rows' was not declared in this scope
/usr/include/mysql++/result.h: At global scope:
/usr/include/mysql++/result.h:457: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/result.h:458: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/result.h: In member function 'mysqlpp::ResUse& mysqlpp::ResUse::operator=(const mysqlpp::ResUse&)':
/usr/include/mysql++/result.h:627: error: 'const class mysqlpp::ResUse' has no member named 'result_'
/usr/include/mysql++/query.h: At global scope:
/usr/include/mysql++/query.h:700: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/query.h:701: error: 'my_ulonglong' does not name a type
/usr/include/mysql++/query.h: In member function 'void mysqlpp::Query::storein_sequence(Sequence&, const char*)':
/usr/include/mysql++/query.h:732: error: 'MYSQL_ROW' was not declared in this scope
/usr/include/mysql++/query.h:732: error: expected `;' before 'd'
/usr/include/mysql++/query.h:733: error: 'd' was not declared in this scope
/usr/include/mysql++/query.h:735: error: 'd' was not declared in this scope
/usr/include/mysql++/query.h:735: error: 'class mysqlpp::ResUse' has no member named 'raw_result'
/usr/include/mysql++/query.h:735: error: there are no arguments to 'mysql_fetch_lengths' that depend on a template parameter, so a declaration of 'mysql_fetch_lengths' must be available
/usr/include/mysql++/query.h:735: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/usr/include/mysql++/query.h: In member function 'void mysqlpp::Query::storein_set(Set&, const char*)':
/usr/include/mysql++/query.h:757: error: 'MYSQL_ROW' was not declared in this scope
/usr/include/mysql++/query.h:757: error: expected `;' before 'd'
/usr/include/mysql++/query.h:758: error: 'd' was not declared in this scope
/usr/include/mysql++/query.h:760: error: 'd' was not declared in this scope
/usr/include/mysql++/query.h:760: error: 'class mysqlpp::ResUse' has no member named 'raw_result'
/usr/include/mysql++/query.h:760: error: there are no arguments to 'mysql_fetch_lengths' that depend on a template parameter, so a declaration of 'mysql_fetch_lengths' must be available
printdata.h: At global scope:
printdata.h:35: error: expected unqualified-id before '&' token
printdata.h:35: error: expected ',' or '...' before '&' token
printdata.h:37: error: ISO C++ forbids declaration of 'parameter' with no type
printdata.h:38: error: variable or field 'print_stock_rows' declared void
printdata.h:38: error: 'StoreQueryResult' is not a member of 'mysqlpp'
printdata.h:38: error: 'res' was not declared in this scope
simple1.cpp: In function 'int main(int, char**)':
simple1.cpp:52: error: no matching function for call to 'mysqlpp::Connection::query(const char [23])'
/usr/include/mysql++/connection.h:199: note: candidates are: mysqlpp::Query mysqlpp::Connection::query()
simple1.cpp:53: error: 'StoreQueryResult' is not a member of 'mysqlpp'
simple1.cpp:53: error: expected `)' before 'res'
simple1.cpp:55: error: 'res' was not declared in this scope



alguma sugestão???
acho que vou usar mysql em C mesmo...


8. estranho demais

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 12/05/2008 - 16:51h

-bash: /usb/bin/mysql_config: No such file or directory (ele ta falando que o mysql_config não ta la não)
estranho demais cara.
Não to no linux agora mas assim que tiver vejo se consigo ver se tem mais alguma config a ver.

Você falou do C... ele compila os exemplos em C?


9. concordo

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 12/05/2008 - 16:57h

realmente, muito estranho...

os programas que eu fiz em C estão sendo compilados corretamente. Para eles eu uso:
#g++ teste.c -lmysqlclient
e pronto já sai o a.out e eu o executo e tudo sai tudo nos conformes... mais se vc puder mesmo assim ver pra mim oque mais q pode ser eu agradeço

Abração...


10. ae

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 12/05/2008 - 17:09h

você ja tentou linkar os progs em C++ com o
-lmysqlclient
Tenta usar ele ao inves do:
-lmysqlpp
Ou ainda usar as 2 libs


11. bem lembrado

Paulo Marcos Trentin
paulopmt1

(usa Debian)

Enviado em 12/05/2008 - 17:58h

É eu já tinha tentado c++ com -lmysqlclient, só não tinha tentado com as duas juntas. Mais dos 2 modos dá exatamente o mesmo erro, tanto com a mysqlclient quanto a mysqlpp...

até agora não consegui compilar, e o pior que documentação a respeito, mesmo em inglês, tá difícil de achar...


12. Re: Erro compilar exemplos mysql++ com g++

Rodrigo Ferreira Valentim
engos

(usa openSUSE)

Enviado em 13/05/2008 - 10:32h

Como a Debian é uma distro bem infeliz para tudo (menos para base de outras), instalo tudo na mão para obter as versões mais recentes de forma estável, por isso não estava tendo seu problema.

Quando instalei a biblioteca do MySLQ pela Debian via aptitude, aconteceu o mesmo comigo.

O que fiz foi entrar no diretório dos exemplos e compilar da seguinte forma:

cd /usr/share/doc/libmysql++-dev/examples

/usr/share/doc/libmysql++-dev/examples# g++ -lmysqlpp -I/usr/include/mysql -I/usr/include/mysql++ simple1.cpp -o simple


Com isso ele me gerou apenas um erro:
simple1.cpp:(.text+0x1de): undefined reference to `parse_command_line(int, char**, char const**, char const**, char const**, char const**, char const*)'
collect2: ld returned 1 exit status


Pesquisando verifiquei que esses exemplos não devem funcionar compilados dessa forma, por isso devem ser adaptados.

No caso desse meu erro basta substituir essa função parse_command_line, que tem como objetivo pegar os 4 parametros passados pela execução do programa e os colocar nas suas devidas variáveis.

De uma olhada no simple1.cpp, linha 43 que você vai entender melhor, basta criar essa função no simple1.cpp, antes do main, que deve compilar e funcionar corretamente.

[]s



01 02



Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts