Reputation: 11
I have spent already 4 days trying to understand how to connect from VS 2012. My program is written on C++, it connects to Mysql and insert in it records from text file. Problem: 1) I cant compile, it gives me linking mistakes:
1>DataTransformXYZtoDatabase.obj : error LNK2001: unresolved external symbol _mysql_close@4 1>DataTransformXYZtoDatabase.obj : error LNK2001: unresolved external symbol _mysql_query@8 1>DataTransformXYZtoDatabase.obj : error LNK2001: unresolved external symbol _mysql_real_connect@32 1>DataTransformXYZtoDatabase.obj : error LNK2001: unresolved external symbol _mysql_init@4
So what I have done. I used staical library. My actions:
I created win32 console application in release mode
In Additional Include Directories added MySQL include/ catalog. ( C:\MySQL\MySQL Server 5.6\include)
Link/General/Additional library directories / I wrote C:\Program Files\MySQL\MySQL Server 5.6\lib\opt
Than Link/ input I wrote mysqlcppconn-static.lib и libmysql.lib.
C++/Preprocessor I wrote CPPCONN_PUBLIC_FUNC=
Also I added mysqlcppconn-static.lib и libmysql.lib to my exe file directory.
I included the following headers :
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <boost\lexical_cast.hpp>
#include <mysql.h>
#include <windows.h>
//#include "my_global.h"
// MySQL connection
//#include <winSock2.h>
#include <winSock.h>
#include <mysql.h>
#pragma comment(lib, "libmysql.lib")
Please help me if you can. Thank you .
Upvotes: 1
Views: 1106
Reputation: 21
I have also spent 2 days and here is the solution. Instead of console application I've used visual c++ app (the only difference is the defining the include and lib directories)
thats it! do not add any preprocessor commands or static libraries.
Upvotes: 1