Advertisement

03.16.2003 at 04:02AM PST, ID: 20552428
[x]
Attachment Details

How to solve Link Error connecting Mysql with C.

Asked by saraj in C Programming Language

Tags: error, external, l2029, link

Linking...

SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_select_db' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_query' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_free_result' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_error' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_store_result' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_num_fields' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_fetch_row' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_connect' : unresolved external
SAMPCODE.OBJ(c:\raj\cprog\db\sampcode.c) : error L2029: '_mysql_close' : unresolved external

 LINK returned error code 2.
SAMPCODE.EXE - 9 error(s), 0 warning(s)

Below is the program ...

#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>

MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;

int main() {

       int i, count=1;
       char sqlcmd[1024];

       if (!(mysql_connect(&mysql,"localhost","root","password"))) {
               printf("Cant connect to MySQL\nREASON: %s\n", mysql_error(&mysql));
       }

       if (mysql_select_db(&mysql,"mysql")) {
               printf("Cant select database\nREASON: %s\n", mysql_error(&mysql));
       }

       printf("Databases:\n\n");

       sprintf(sqlcmd, "SHOW DATABASES");
       if (mysql_query(&mysql,sqlcmd)) {
               printf("Can't create sql query");
               exit(0);
       }

       if (!(res = mysql_store_result(&mysql))) {
               printf("Cant store data from sql query");
               exit(0);
       }

       while((row = mysql_fetch_row(res))) {
               for (i=0 ; i < (int)mysql_num_fields(res); i++) {
                       printf("%d: %s\n",count,row[0]);
                       count++;
               }
       }

       mysql_free_result(res);
    mysql_close(&mysql);

       printf("Finished..\n");
       
       return 0 ;
}

Start Free Trial
[+][-]03.16.2003 at 04:42AM PST, ID: 8146195

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.16.2003 at 12:16PM PST, ID: 8147351

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: error, external, l2029, link
Sign Up Now!
Solution Provided By: cybeonix
Participating Experts: 3
Solution Grade: A
 
 
[+][-]01.18.2004 at 04:07PM PST, ID: 10142660

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.26.2004 at 05:22PM PST, ID: 10205796

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32