3 messages in com.mysql.lists.plusplusRe: problem compiling program using m...| From | Sent On | Attachments |
|---|---|---|
| Brian Davis | 23 Jul 2007 20:37 | |
| Drew M. | 23 Jul 2007 23:42 | |
| Brian Davis | 24 Jul 2007 18:24 |
| Subject: | Re: problem compiling program using mysql++![]() |
|---|---|
| From: | Drew M. (ghas...@gmail.com) |
| Date: | 07/23/2007 11:42:49 PM |
| List: | com.mysql.lists.plusplus |
Looks like a scope/namespace issue, not a mysql++ issue. The mysql++ library uses the 'mysqlpp' namespace, so you can either add "using namespace mysqlpp;" to the beginning of your file, or add the appropriate namespace scope operators to your code.
This is also why the compiler is complaining about cout - this isn't a mysql++ issue but another namespace issue (in this case, it's the 'std' namespace).
Here's a reference page for your info: http://www.cplusplus.com/doc/tutorial/namespaces.html
See your example below, with a few things added:
On 7/23/07, Brian Davis <bh...@mindspring.com> wrote:
Hello. I'm new to mysql and mysql++. I'm trying to compile the below program for use with mysql++:
#include <iostream> #include <iomanip> #include <mysql++.h>
// either this: using namespace mysqlpp;
int main(void)
{ // -> Create a connection to the database
// or prepend any reference to a mysql++ symbol like so: mysqlpp::Connection con("gamedata","127.0.0.1");
// -> Create a query object that is bound to our connection Query query = con.query();
// -> Assign the query to that object query << "SELECT * FROM paymentinfo";
// -> Store the results from then query Result res = query.store();
// -> Display the results to the console
// -> Show the Field Headings cout.setf(ios::left); cout << setw(6) << "id" << setw(10) << "playerid" << setw(20) << "datepaid" << setw(20) << "type" << setw(20) << "amount" << endl;
Result::iterator i; Row row; // The Result class has a read-only Random Access Iterator for (i = res.begin(); i != res.end(); i++) { row = *i; cout << setw(6) << row["id"] << setw(10) << row["playerid"] << setw(20) << row["datepaid"] << setw(20) << row["type"] << setw(20) << row["amount"] << endl; }
return 1; }
I'm using Mingw/GCC 3.4.2 on Windows XP SP2 with the following command to compile:
C:\Dev-Cpp\mysqlexample1devcpp>g++ -c main.cpp -o main.o-I"Z:\dev-cpp\include" -lmysqlclient -lmysqlpp -lmysqlpp_util -lmysql -L"Z:\dev- cpp\lib"
and I get the below errors:
main.cpp: In function `int main()': main.cpp:10: error: `Connection' undeclared (first use this function) main.cpp:10: error: (Each undeclared identifier is reported only once for each f unction it appears in.) main.cpp:10: error: expected `;' before "con" main.cpp:13: error: `Query' undeclared (first use this function) main.cpp:13: error: expected `;' before "query" main.cpp:16: error: `query' undeclared (first use this function) main.cpp:19: error: `Result' undeclared (first use this function) main.cpp:19: error: expected `;' before "res" main.cpp:25: error: `cout' undeclared (first use this function) main.cpp:25: error: `ios' has not been declared main.cpp:25: error: `left' undeclared (first use this function) main.cpp:26: error: `setw' undeclared (first use this function) main.cpp:30: error: `endl' undeclared (first use this function) main.cpp:32: error: `Result' has not been declared main.cpp:32: error: `iterator' undeclared (first use this function) main.cpp:32: error: expected `;' before "i" main.cpp:33: error: `Row' undeclared (first use this function) main.cpp:33: error: expected `;' before "row" main.cpp:35: error: `i' undeclared (first use this function) main.cpp:35: error: `res' undeclared (first use this function) main.cpp:37: error: `row' undeclared (first use this function)
It seems like I'm not including a header file or not linking to a particular library, but I cannot figure it out. I'm hoping another pair of eyes can help me. Anyone who has a suggestion and the time, I'd be most grateful for your response. Thanks.
Brian
-- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=ghas...@gmail.com




