Okay, so I should probably start off by mentioning that I am using VS 2010 with the MySQL C API in two C++ projects. One project is an API static library I'm creating for providing quicker access to my MySQL database (using the api..), while the other project is a console app that will test the new library. Under both project properties I have set PROPERTIES \ CONFIGURATION PROPERTIES \ C/C++ \ ADDITIONAL INCLUDE LIBRARIES to include the MySQL folder containing the include files (MySQL \ Include). For the test app, I obviously include the header file to my static library as well.
In PROPERTIES \ CONFIGURATION PROPERTIES \ LINKER \ GENERAL, I have included the MySQL library directory (MySQL \ lib \ opt), as well as the static library file for my new library. I also added the necessary lib files for "Additional Dependencies" under "Input" as well for both programs. However, although my static library compiles fine, when I try compiling the test app I still get the following errors:
Error 27 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\Example\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 30 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\Example\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 28 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\Example\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 29 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\Example\MSQLClientTest\server.lib(connect.obj) MSQLClientTest
Error 31 error LNK1120: 4 unresolved externals 1 E:\My Documents\Visual Studio 2010\Projects\Example\Debug\MSQLClientTest.exe 1 MSQLClientTest
Here's a sample of my library code and it's implementation:
server.h
#include <vector>
#include <iostream>
#include <string>
#include <my_global.h>
#include <mysql.h>
namespace Mainframe
{
class User
{
public:
Mainframe::User::User();
Mainframe::User::User(std::string);
int grabInfo();
};
}
Library:
#include "stdafx.h"
#include "server.h"
Mainframe::User::User() {}
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);
}
Test App:
#include "stdafx.h"
#include "server.h"
int main(int argc, char* argv[])
{
Mainframe::User u;
std::cout << u.grabInfo();
std::system("PAUSE");
return 0;
}
Any idea what's causing these errors? A quick Google search reveals that this is a common issue, but not a single forum I looked at seemed to present an applicable solution. Any help would be greatly appreciated.
TIA!