Hey I’ve had nonstop problems with SQL. I’m trying to get some experience because I know it’s a vital part of the industry. I got it working with C#, but now I’m working on connecting to a database in c++. I have the project properly linked and what not. Here’s my code and the errors I’m getting.
#include "stdafx.h"
#include <mysql.h>
#include <iostream>
MYSQL mysql;
MYSQL_RES result;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
mysql_init(&mysql);
if(!mysql_real_connect(&mysql, "localhost", "root", "*******", "MyDatabse", 0, NULL, 0))
{
printf("Failed to connect");
}
return 0;
}
and the errors:
Error 1 error LNK2001: unresolved external symbol _mysql_real_connect@32 c:\Users\Zack-074\documents\visual studio 2010\Projects\MySql\MySql\MySql.obj
Error 2 error LNK2001: unresolved external symbol _mysql_init@4 c:\Users\Zack-074\documents\visual studio 2010\Projects\MySql\MySql\MySql.obj
Error 3 error LNK1120: 2 unresolved externals c:\users\zack-074\documents\visual studio 2010\Projects\MySql\Debug\MySql.exe 1
I really appreciate the help.
Those are linker errors. In other words, you don’t appear to be having any problem compiling to object files but are running into difficulties when attempting to link those object files into an executable.
One solution that pops immediately to mind is to manually specify the location and/or name of the library you wish to link against. In VS2010, right-click on the project you’re working on and select Properties. From there, open up the linker options and specify the directory in which the library you want to link against.