title: Visual studio C++ connect to MYSQL server
body: <p>I got errors when T try to run my c++ program to connect to MYSQL server. Here is my code.</p>
  
  <pre><code> #include "stdafx.h"
   #include &lt;opencv2/highgui/highgui.hpp&gt; 
   #include "opencv2/imgproc/imgproc.hpp" 
   #include "opencv2/opencv.hpp" 
   #include &lt;cmath&gt; 
   #include &lt;iostream&gt; 
   #include "my_global.h" 
   #include "mysql.h"
  
   int main() {MYSQL *conn;
  MYSQL_RES *res;
  MYSQL_ROW row;
  char *server = "server";
  char *user = "user";
  char *password = "password";  // got tot keep my data secret
  char *database = "cpp_test";
  conn = mysql_init(NULL);
  
  // connect to database
  if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
  {
      fprintf(stderr, "%s\n", mysql_error(conn));
      return -1;
  }
  
  // send SQL query
  if(mysql_query(conn, "select * from cpp_testTAB"))
  {
      fprintf(stderr, "%s\n", mysql_error(conn));
      return -1;
  }
  
  res = mysql_use_result(conn);
  
  // output table name
  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) != NULL)
  {
      printf("%s %s %s %s\n", row[0], row[1], row[2], row[3]);
  }
  
  // close connection
  mysql_free_result(res);
  mysql_close(conn);
  return 0;
  }
  </code></pre>
  
  <p>Here is my additional include directories</p>
  
  <pre><code>C:\Program Files (x86)\MySQL\MySQL Server 5.6\include
  C:\Program Files (x86)\MySQL\Connector.C++ 1.1\include
  </code></pre>
  
  <p>Additional Library Directories</p>
  
  <pre><code>C:\Program Files (x86)\MySQL\MySQL Server 5.6\lib
  C:\Program Files (x86)\MySQL\Connector.C++ 1.1\lib\opt
  </code></pre>
  
  <p>Additional Dependencies</p>
  
  <pre><code>libmysql.lib
  mysqlcppconn-static.lib
  </code></pre>
  
  <p>There are the errors that i got when I try  to run the program. </p>
  
  <pre><code>Error   1   error LNK2019: unresolved external symbol mysql_close referenced in function main   
  Error   2   error LNK2019: unresolved external symbol mysql_free_result referenced in function main 
  Error   3   error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main   
  Error   4   error LNK2019: unresolved external symbol mysql_use_result referenced in function main  
  Error   5   error LNK2019: unresolved external symbol mysql_query referenced in function main   
  Error   6   error LNK2019: unresolved external symbol mysql_error referenced in function main   
  Error   7   error LNK2019: unresolved external symbol mysql_real_connect referenced in function main
  Error   8   error LNK2019: unresolved external symbol mysql_init referenced in function main
  
  Error   9   error LNK1120: 8 unresolved externals   C:\Users\Lahiru\documents\visual studio 2010\Projects\Level4-Project\x64\Debug\Level4-Project.exe
  </code></pre>
  
  <p>I am unable to solve this problem. if anyone can show me error or sample tutorial link that will be great. </p>