MySQL Forums
Forum List  »  Source, Builds, Binaries

Problem linking
Posted by: shawn andrews
Date: May 17, 2013 10:13AM

I'm trying to use C++ and SQL in Visual Studio, and trying to load a SQL example to make sure it's working.

This is the example project taken from [url="[url]http://www.nitecon.com/tutorials-articles/develop/cpp/c-mysql-beginner-tutorial/"[/url];]link[/url]

[code]

#include "my_global.h" // Include this file first to avoid problems
#include "mysql.h" // MySQL Include File
#define SERVER "localhost"
#define USER "username"
#define PASSWORD "password"
#define DATABASE "databasename"

#include <iostream>
using namespace std;

#include "my_global.h" // Include this file first to avoid problems
#include "mysql.h" // MySQL Include File
#define SERVER "localhost"
#define USER "username"
#define PASSWORD "password"
#define DATABASE "databasename"

int main()
{
MYSQL *connect; // Create a pointer to the MySQL instance
connect=mysql_init(NULL); // Initialise the instance
/* This If is irrelevant and you don't need to show it. I kept it in for Fault Testing.*/
if(!connect) /* If instance didn't initialize say so and exit with fault.*/
{
fprintf(stderr,"MySQL Initialization Failed");
return 1;
}
/* Now we will actually connect to the specific database.*/

connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0);
/* Following if statements are unneeded too, but it's worth it to show on your
first app, so that if your database is empty or the query didn't return anything it
will at least let you know that the connection to the mysql server was established. */

if(connect){
printf("Connection Succeeded\n");
}
else{
printf("Connection Failed!\n");
}
MYSQL_RES *res_set; /* Create a pointer to recieve the return value.*/
MYSQL_ROW row; /* Assign variable for rows. */
mysql_query(connect,"SELECT * FROM TABLE");
/* Send a query to the database. */
unsigned int i = 0; /* Create a counter for the rows */

res_set = mysql_store_result(connect); /* Receive the result and store it in res_set */

unsigned int numrows = mysql_num_rows(res_set); /* Create the count to print all rows */

/* This while is to print all rows and not just the first row found, */

while ((row = mysql_fetch_row(res_set)) != NULL){
printf("%s\n",row != NULL ?
row : "NULL"); /* Print the row data */
}
mysql_close(connect); /* Close and shutdown */

system("pause");
return 0;
}

[/code]

Errors:
1>------ Build started: Project: connectSQL, Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_num_rows@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_store_result@4 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main
1>C:\Users\Shawn\Documents\Visual Studio 2010\Projects\connectSQL\Debug\connectSQL.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Include/Headers/Libs:
VC++ Directories->Include Directory->C:\Program Files\MySQL\MySQL Server 5.6\include
VC++ Directories->Library Directory->C:\Program Files\MySQL\MySQL Server 5.6\lib
VC++ Directories->Bin Directory->C:\Program Files\MySQL\MySQL Server 5.6\bin

Linker->Input->Additional Dependencies->libmysql.lib

And I put libmysql.lib in Program Files(x86)->Microsoft Visual Studio 10.0->VC->lib which is where I believe i'm supposed to put it.

Options: ReplyQuote


Subject
Views
Written By
Posted
Problem linking
2984
May 17, 2013 10:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.