...

View Full Version : C++ - linking errors (unresolved tokens)



return 0
08-27-2009, 09:00 PM
here is my .cpp file code

#include "NSQLCON.h"

int SQLConnect()
{
SQLCON CS;
CS.pConnection = mysql_init(NULL);

try
{
// Establish the connection to the database server.
mysql_real_connect(CS.pConnection, "localhost", "root", "lol100", "test", 3306, NULL, 0);
}
catch (const mysqlpp::BadConversion& er)
{
// Handle bad conversions
cerr << "Conversion error: " << er.what() << endl <<
"\tretrieved data size: " << er.retrieved <<
", actual size: " << er.actual_size << endl;
return -1;
}
catch (const mysqlpp::Exception& er)
{
// Catch-all for any other MySQL++ exceptions
cerr << "Error: " << er.what() << endl;
system("pause");
return -1;
}
return 0;
}
heres my header file

#include "stdafx.h"

class SQLCON
{
public:
MYSQL *pConnection;
int SQLConnect();
};
i call the SQLConnect() method in Main()

SQLCON C;
C.pConnection = mysql_init(NULL);
C.SQLConnect();

i get this error whilst debugging

Main.obj : error LNK2028: unresolved token (0A000729) "public: int __thiscall SQLCON::SQLConnect(void)" (?SQLConnect@SQLCON@@$$FQAEHXZ) referenced in function "int __cdecl main(int,char * * const)" (?main@@$$HYAHHQAPAD@Z)
Main.obj : error LNK2019: unresolved external symbol "public: int __thiscall SQLCON::SQLConnect(void)" (?SQLConnect@SQLCON@@$$FQAEHXZ) referenced in function "int __cdecl main(int,char * * const)" (?main@@$$HYAHHQAPAD@Z)

i've been racking my brain over this for two days, and I can't seem to find a solution. any help would be appreciated. thanks.

oracleguy
08-27-2009, 10:13 PM
Spotted it right away:


#include "NSQLCON.h"

int SQLCON::SQLConnect()
{


Also that variable pConnection in your class should be private or protected and not public.


And why are you using the MySQL API directly but catching MySQL++ exceptions?

return 0
08-28-2009, 12:54 AM
Spotted it right away:


#include "NSQLCON.h"

int SQLCON::SQLConnect()
{


Also that variable pConnection in your class should be private or protected and not public.


And why are you using the MySQL API directly but catching MySQL++ exceptions?
Haha, thanks; I've never had that error before, so y'know...and I don't have a clue tbh. I'm using MySQL++ to handle queries etc, but I can't find a decent user guide that explains how to connect to the db via MySQL++ and so on. their user doc isn't very explanitory. (if you have one, please, do link me to it; thanks). http://dev.mysql.com/doc/refman/5.0/en/apis-cplusplus.html according to that, aren't I supposed to be using MySQL++ to connect?

also which method do you recommend I use? MySQL++ or the standard API?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum