Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    C++ - linking errors (unresolved tokens)

    here is my .cpp file code
    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
    Code:
    #include "stdafx.h"
    
    class SQLCON
    {
    public:
    	MYSQL *pConnection;
    	int SQLConnect();
    };
    i call the SQLConnect() method in Main()
    Code:
    	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.
    Last edited by oracleguy; 08-27-2009 at 09:11 PM.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Spotted it right away:

    Code:
    #include "NSQLCON.h"
    
    int SQLCON::SQLConnect()
    {
    Also that variable pConnection in your class should be private or protected and not public.


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

  • Users who have thanked oracleguy for this post:

    return 0 (08-28-2009)

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    Spotted it right away:

    Code:
    #include "NSQLCON.h"
    
    int SQLCON::SQLConnect()
    {
    Also that variable pConnection in your class should be private or protected and not public.


    Edit: 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/...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?
    Last edited by return 0; 08-28-2009 at 12:00 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •