Okay.. so I need some help with my C++ class. I've been using tutorials online to help me, but now I'm just plain stuck. I have the following code:
server.h:
#ifndef USER_H
#define USER_H
#include <vector>
#include <iostream>
#include <string>
#include <my_global.h>
#include <mysql.h>
namespace Mainframe
{
class User
{
public:
Mainframe::User::User(std::string);
int grabInfo();
};
}
#endif
server.cpp:
#include "stdafx.h"
#include "server.h"
MYSQL *conn;
Mainframe::User::User(std::string id)
{
conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "root", "password", "users", 0, NULL, 0);
}
int Mainframe::User::grabInfo()
{
return mysql_query(conn, "SELECT * FROM users");
mysql_close(conn);
}
Now, as you may have noticed, I am using MySQL C API for database calling. This is my first time using it. Anyway, every time I try to compile I get the error:
error C2512: no appropriate default constructor available
So I did some research and put this before the constructor in my header file:
Mainframe::User::User();
I then added the referenced function to my cpp file:
Mainframe::User::User() { }
And I compile. The default constructor error is gone, but I'm instead left with this:
Error 5 error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: __thiscall Mainframe::User::User(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0User@Mainframe@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 8 error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "public: int __thiscall Mainframe::User::grabInfo(void)" (?grabInfo@User@Mainframe@@QAEHXZ) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 6 error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: __thiscall Mainframe::User::User(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0User@Mainframe@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 7 error LNK2019: unresolved external symbol _mysql_close@4 referenced in function "public: int __thiscall Mainframe::User::grabInfo(void)" (?grabInfo@User@Mainframe@@QAEHXZ) E:\My Documents\Visual Studio 2010\Projects\LoveBird\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 9 error LNK1120: 4 unresolved externals 1 E:\My Documents\Visual Studio 2010\Projects\LoveBird\Debug\MSQLClientTest.exe 1 MSQLClientTest
I have no idea what's wrong! Please help me. I'm pretty new to C++ and forgive me if this is a stupid question. Thanks in advance.