Search code examples
c++mysqlvisual-studio-2010linkerconnector

MySQL Connector C linking problem on VS2010


I am beginning on MySQL, and I encountered the error message while compiling the code:

error LNK2001: unresolved external symbol _mysql_init@4

I have searched the web, and did everything that seems to be the problem.

#include <my_global.h>
#include <mysql.h>
#define NULL 0
int main() {
  MYSQL * sql = mysql_init(NULL);
  return 0;
}

I have checked that I have been using /MT option. Include, link directory added. I use release, and included "lib\opt".

libmysql.lib is in linker->input->additional dependency.

I have been using windows 7 x64 with VS2010 x86, and downloaded and installed MySQL Connector/C

Windows (x86, 64-bit), MSI Installer 6.0.2 (mysql-connector-c-6.0.2-winx64.msi)

What might be the problem, can anybody help?


Solution

  • After a careful investigation, I found that the problem raised from the x64 settings. x64 compilation option should be turned on when compiling an x64 project. In this case, platform should be switched from win32 to x64, and in project->properties->linker->advanced->target machine: x86 should be set to x64.