I gave myself a project to get familiar with Windows Programming and Visual Studio. I am having trouble linking to the MySQL libraries so that I can use it in my project. I keep getting a LNK2019 error, which most likely means that I am not linking the .lib files properly. I've already set its configuration to include the include directories and library directories. (I also tried different combinations of setting VC++ Directories and C/C++ / Linker.)
Error 1 error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function "public: void __thiscall Database::connect_db(void)" (?connect_db@Database@@QAEXXZ) D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\swtPrice Server\Database.obj
Error 2 error LNK2019: unresolved external symbol _mysql_init@4 referenced in function "public: void __thiscall Database::connect_db(void)" (?connect_db@Database@@QAEXXZ) D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\swtPrice Server\Database.obj
Error 3 error LNK1120: 2 unresolved externals D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.exe 1
Here is a snippet of code that I copied online and trying to compile:
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;
mysql_init(&mysql);
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,"localhost","bainm","not_telling","cpp_data",0,0,0);
if (connection == NULL) {
//cout << mysql_error(&mysql) << endl;
//return 1;
}
I configured my project to include the MySQL's include directory. This is how it looks like in the command line under the C/C++ tab:
/I"D:\Program Files\MySQL\MySQL Server 5.5\include" /ZI /nologo /W1 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\swtPrice Server.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue
I configured my to include the MySQL's Library directory. This is how it looks like in the command line under the Linker:
/OUT:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.exe" /NOLOGO /LIBPATH:"D:\Program Files\MySQL\MySQL Server 5.5\lib" "D:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\swtPrice Server.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.pdb" /SUBSYSTEM:CONSOLE /PGD:"D:\Media\Documents\Visual Studio 2010\Projects\swtPrice Server\Debug\swtPrice Server.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
This is how the mySQL library directory looks like:
Directory of D:\Program Files\MySQL\MySQL Server 5.5\lib
05/06/2011 10:38 AM <DIR> .
05/06/2011 10:38 AM <DIR> ..
05/06/2011 10:38 AM <DIR> debug
03/31/2011 04:53 PM 4,177,408 libmysql.dll
03/31/2011 04:53 PM 23,920 libmysql.lib
03/31/2011 04:52 PM 10,625,266 mysqlclient.lib
05/06/2011 10:38 AM <DIR> plugin
Any help is appreciated. Thank you in advance for any help.