• 9
• 16
• 15
• 12
• 9

# help compiling simple program using MySQL++

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i have an SQL server up and running and i want to connect to it from a C++ program. anyway, im having a hell of a time trying to get a simple program to compile. im running on Windows XP and using VS.net 2k3. here is the source (an example program that came with the API):
#include "util.h"

#include <mysql++.h>

#include <iostream>
#include <iomanip>

using namespace std;

int
main(int argc, char *argv[])
{
// The full format for the Connection constructor is
// Connection(cchar *db, cchar *host="",
//            cchar *user="", cchar *passwd="")
// You may need to specify some of them if the database is not on
// the local machine or you database username is not the same as your
try {
mysqlpp::Connection con(mysqlpp::use_exceptions);
connect_sample_db(argc, argv, con);

mysqlpp::Query query = con.query();
// This creates a query object that is bound to con.

query << "select * from stock";
// You can write to the query object like you would any other ostrem

mysqlpp::Result res = query.store();
// Query::store() executes the query and returns the results

cout << "Query: " << query.preview() << endl;
// Query::preview() simply returns a string with the current query
// string in it.

cout << "Records Found: " << res.size() << endl << endl;

mysqlpp::Row row;
cout.setf(ios::left);
cout << setw(17) << "Item"
<< setw(4) << "Num"
<< setw(7) << "Weight"
<< setw(7) << "Price" << "Date" << endl << endl;

mysqlpp::Result::iterator i;
// The Result class has a read-only Random Access Iterator
for (i = res.begin(); i != res.end(); i++) {
row = *i;
cout << setw(17) << row[0].c_str()
<< setw(4) << row[1].c_str()
<< setw(7) << row.lookup_by_name("weight").c_str()
// you can use either the index number or column name when
// retrieving the colume data as demonstrated above.
<< setw(7) << row[3].c_str()
<< row[4] << endl;
}
}
// handle any connection or query errors that may come up
#ifdef USE_STANDARD_EXCEPTION
cerr << "Error: " << er.what() << endl;
#else
cerr << "Error: " << er.error << endl;
#endif
return -1;
}
#ifdef USE_STANDARD_EXCEPTION
cerr << "Error: " << er.what() << "\"." << endl
<< "retrieved data size: " << er.retrieved
<< " actual data size: " << er.actual_size << endl;
#else
cerr << "Error: Tried to convert \"" << er.data << "\" to a \""
<< er.type_name << "\"." << endl;
#endif
return -1;
}
#ifdef USE_STANDARD_EXCEPTION
catch (exception & er) {
cerr << "Error: " << er.what() << endl;
return -1;
}
#endif

return 0;
}


Compiling...
main.cpp
c:\Documents and Settings\doo\Desktop\MySQL++\mysql++-1.7.21\lib\result.h(174) : warning C4244: 'return' : conversion from 'my_ulonglong' to 'int', possible loss of data
main.obj : error LNK2019: unresolved external symbol "public: __thiscall mysqlpp::Connection::~Connection(void)" (??1Connection@mysqlpp@@QAE@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl mysqlpp::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class mysqlpp::ColData_Tmpl<class mysqlpp::const_string> const &)" (??6mysqlpp@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABV?$ColData_Tmpl@Vconst_string@mysqlpp@@@0@@Z) referenced in function _main main.obj : error LNK2019: unresolved external symbol "public: class mysqlpp::ColData_Tmpl<class mysqlpp::const_string> const __thiscall mysqlpp::Row::lookup_by_name(char const *)const " (?lookup_by_name@Row@mysqlpp@@QBE?BV?$ColData_Tmpl@Vconst_string@mysqlpp@@@2@PBD@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: class mysqlpp::Query __thiscall mysqlpp::Connection::query(void)" (?query@Connection@mysqlpp@@QAE?AVQuery@2@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "void __cdecl connect_sample_db(int,char * * const,class mysqlpp::Connection &,char const *)" (?connect_sample_db@@YAXHQAPADAAVConnection@mysqlpp@@PBD@Z) referenced in function _main
main.obj : error LNK2001: unresolved external symbol "public: virtual class mysqlpp::ColData_Tmpl<class mysqlpp::const_string> const __thiscall mysqlpp::Row::operator[](unsigned int)const " (??ARow@mysqlpp@@UBE?BV?$ColData_Tmpl@Vconst_string@mysqlpp@@@1@I@Z) main.obj : error LNK2001: unresolved external symbol "public: virtual unsigned int __thiscall mysqlpp::Row::size(void)const " (?size@Row@mysqlpp@@UBEIXZ) main.obj : error LNK2019: unresolved external symbol "public: __thiscall mysqlpp::ResUse::~ResUse(void)" (??1ResUse@mysqlpp@@QAE@XZ) referenced in function "public: virtual __thiscall mysqlpp::Result::~Result(void)" (??1Result@mysqlpp@@UAE@XZ) main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall mysqlpp::SQLQuery::str(class mysqlpp::SQLQueryParms &)" (?str@SQLQuery@mysqlpp@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAVSQLQueryParms@2@@Z) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall mysqlpp::Query::preview(void)" (?preview@Query@mysqlpp@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?\$allocator@D@2@@std@@XZ)
main.obj : error LNK2019: unresolved external symbol "public: class mysqlpp::Result __thiscall mysqlpp::Query::store(class mysqlpp::SQLQueryParms &,enum mysqlpp::query_reset)" (?store@Query@mysqlpp@@QAE?AVResult@2@AAVSQLQueryParms@2@W4query_reset@2@@Z) referenced in function "public: class mysqlpp::Result __thiscall mysqlpp::Query::store(enum mysqlpp::query_reset)" (?store@Query@mysqlpp@@QAE?AVResult@2@W4query_reset@2@@Z)


does anyone know what im missing? im not linking against any libraries, and i think that could be a problem.. but it didn't come with any .lib files, and im not sure if i have to compile one myself or not. i tried compiling the project that came with MySQL++ but got errors. so far i just set my include directory to include the MySQL++ 'lib' folder. i also had it include the MySQL C API as well, although im not sure if that should matter. thanks for any help.

##### Share on other sites
you probably have to link with some libraries, what files did it come with, and what errors did you get when you tried to compile it?

##### Share on other sites
in the main folder it comes with a visual studio project called mysql++ (which is the name of the API). im guessing i have to compile this into a lib.. so i open the project but it gives me 14 linker errors. the workspace actually has about that many projects in it. the linker error looks like this:

LINK : fatal error LNK1181: cannot open input file '\Documents and Settings\doo\Desktop\MySQL++\mysql++-1.7.21\Debug\mysql++.lib'
error C2660: 'mysql_shutdown' : function does not take 1 arguments

and, i also get this error, but this one i only get once:

c:\MySQL++\mysql++-1.7.21\lib\connection.cc(97) : error C2660: 'mysql_shutdown' : function does not take 1 arguments

thanks for any help.

##### Share on other sites
Looks like your versions of MySQL and MySQL++ are out of sync. Either that or it is incompatible with that compiler (or needs options changing etc)

Have you tried actually reading the instructions? Maybe it tells you how to compile it.

Mark

##### Share on other sites
i don't see how they can be out of sync, since i just downloaded both of them.

also, thats the problem. there isn't any info in the docs on setting this up. does anyone have any clue what to do? its really frustrating that i cant set this up, been trying for a few days now..

thanks a lot for anymore help.