Linker error when connecting C to mysql


I want to connect C to mysql using the following code:

#include <C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\my_global.h>
#include <C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql.h>

#include <stdio.h> 
MYSQL *conn;    /* pointer to connection handler */

int main ( int argc, char *argv[] )
{
    conn = mysql_init ( NULL );
    mysql_real_connect (
            conn,"localhost","root","","operator", 3306, NULL,0 );        
    mysql_close ( conn );
    return 0;
}

      

When I try to compile I get:

Error   3   error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main   C:\Users\kristel\Documents\Visual Studio 2010\Projects\database\database\database.obj   database

Error   4   error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main    C:\Users\kristel\Documents\Visual Studio 2010\Projects\database\database\database.obj   database

      

It seems to be missing something, but I don't know when.

enter image description here

I added mysqllib.lib like in the picture but the problem is still not resolved.

One more question: While doing my searches, I found something regarding cmake.Is there some connection between my error and cmake?
Thank.

+3


source to share


1 answer


While you have included the mySQL headers in your code, you have not included the mySQL library in your link parameters.



+2


source







All Articles