unknown errors
Posted by: Paul Kioko
Date: April 06, 2012 02:25PM

I have look everywhere one here and tried every thing here and other places and I still get all these errrors why, please somebody help.



>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_close@4 referenced in function _main
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_get_server_info@4 referenced in function _main
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_init@4 referenced in function _main
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_free_result@4 referenced in function "void __cdecl showTables(struct st_mysql *)" (?showTables@@YAXPAUst_mysql@@@Z)
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_fetch_row@4 referenced in function "void __cdecl showTables(struct st_mysql *)" (?showTables@@YAXPAUst_mysql@@@Z)
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_list_tables@8 referenced in function "void __cdecl showTables(struct st_mysql *)" (?showTables@@YAXPAUst_mysql@@@Z)
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_num_fields@4 referenced in function "void __cdecl showContents(struct st_mysql *,char const *)" (?showContents@@YAXPAUst_mysql@@PBD@Z)
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_use_result@4 referenced in function "void __cdecl showContents(struct st_mysql *,char const *)" (?showContents@@YAXPAUst_mysql@@PBD@Z)
1>TESTDBCPP.obj : error LNK2019: unresolved external symbol _mysql_query@8 referenced in function "void __cdecl showContents(struct st_mysql *,char const *)" (?showContents@@YAXPAUst_mysql@@PBD@Z)
1>c:\users\sasuke\documents\visual studio 2010\Projects\TESTDBCPP\Debug\TESTDBCPP.exe : fatal error LNK1120: 10 unresolved externals

Here's my code:
#include "stdafx.h"

#include <stdio.h>
#include <iostream>
#define W32_LEAN_AND_MEAN
#include <winsock2.h>
#include "mysql.h"


//#define TABLE_OF_INTEREST "some_table"
/*#define SERVER_NAME "MySQL Server 5.0"
#define DB_USER "root"
#define DB_USERPASS "avisys"
#define DB_NAME "avisys"
*/
/*
#define SERVER_NAME "192.168.0.14"
#define TABLE_OF_INTEREST "db"
#define DB_NAME "mysql"
#define DB_USER NULL
#define DB_USERPASS NULL

*/

#define TABLE_OF_INTEREST "last_data"
#define SERVER_NAME "mysql"
#define DB_USER NULL
#define DB_USERPASS "avisys"
#define DB_NAME "mysql"



void showTables(MYSQL*);
void showContents(MYSQL*,const char*);


int main(int argc, char* argv[])
{

MYSQL *hnd=0; // mysql connection handle
const char *sinf=NULL; // mysql server information

hnd = mysql_init(NULL);
if (NULL == mysql_real_connect(hnd,"localhost",DB_USER,DB_USERPASS,DB_NAME,0,NULL,0))
{
fprintf(stderr,"Problem encountered connecting to the %s database on %s.\n",DB_NAME,SERVER_NAME);
}
else
{
fprintf(stdout,"Connected to the %s database on %s as user '%s'.\n",DB_NAME,SERVER_NAME,DB_USER);
sinf = mysql_get_server_info(hnd);

if (sinf != NULL)
{
fprintf(stdout,"Got server information: '%s'\n",sinf);
showTables(hnd);
showContents(hnd,TABLE_OF_INTEREST);
}
else
{
fprintf(stderr,"Failed to retrieve the server information string.\n");
}

mysql_close(hnd);
}
return 0;
}


void showTables(MYSQL *handle)
{
MYSQL_RES *result=NULL; // result of asking the database for a listing of its tables
MYSQL_ROW row; // one row from the result set

result = mysql_list_tables(handle,NULL);
row = mysql_fetch_row(result);
fprintf(stdout,"Tables found:\n\n");
while (row)
{
fprintf(stdout,"\t%s\n",row[0]);
row = mysql_fetch_row(result);
}
mysql_free_result(result);

fprintf(stdout,"\nEnd of tables\n");

return;
}

void showContents
(
MYSQL *handle,
const char *tbl
)
{
MYSQL_RES *res=NULL; // result of querying for all rows in table
MYSQL_ROW row; // one row returned
char sql[1024], // sql statement used to get all rows
commastr[2]; // to put commas in the output
int i,numf=0; // number of fields returned from the query

sprintf_s(sql,"select * from %s",tbl);
fprintf(stdout,"Using sql statement: '%s' to extract all rows from the specified table.\n",sql);

if (!mysql_query(handle,sql))
{
res = mysql_use_result(handle);
if (res)
{
numf = mysql_num_fields(res);
row = mysql_fetch_row(res);
fprintf(stdout,"Rows returned:\n\n");
while (row)
{
commastr[0]=commastr[1]=(char)NULL;
for (i=0;i<numf;i++)
{
if (row == NULL)
{
fprintf(stdout,"%sNULL",commastr);
}
else
{
fprintf(stdout,"%s%s",commastr,row);
}
commastr[0]=',';
}
fprintf(stdout,"\n");

row = mysql_fetch_row(res);
}
fprintf(stdout,"\nEnd of rows\n");

mysql_free_result(res);
}
else
{
fprintf(stderr,"Failed to use the result acquired!\n");
}
}
else
{
fprintf(stderr,"Failed to execute query. Ensure table is valid!\n");
}

return;
}

Options: ReplyQuote


Subject
Views
Written By
Posted
unknown errors
1664
April 06, 2012 02:25PM


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.