You are not logged in.

#1 2005-10-25 17:22:38

fluke
Member
From: Shaoguan Univ., PRC
Registered: 2005-08-12
Posts: 241
Website

What's wrong! about MySQL C APIs

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

int main()
{ 
    MYSQL mysql;

    mysql_init(&mysql);
    mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
    if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
    {
        fprintf(stderr, "Failed to connect to database: Error: %sn",
            mysql_error(&mysql));
    }

    return 0;
}

This code are from mysql manual.
When I try to compile it, I get the following message:

/tmp/ccojokYy.o(.text+0x29): In function `main':
: undefined reference to `mysql_init'
/tmp/ccojokYy.o(.text+0x47): In function `main':
: undefined reference to `mysql_options'
/tmp/ccojokYy.o(.text+0x8d): In function `main':
: undefined reference to `mysql_real_connect'
/tmp/ccojokYy.o(.text+0xa4): In function `main':
: undefined reference to `mysql_error'
collect2: ld returned 1 exit status

Offline

#2 2005-10-25 18:27:01

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: What's wrong! about MySQL C APIs

What command line did you use to compile?
Did  you linked with the mysql library?

Offline

#3 2005-10-25 20:43:58

demonus
Member
Registered: 2005-01-31
Posts: 62

Re: What's wrong! about MySQL C APIs

gcc source_file.c -lmysqlclient

Offline

#4 2005-10-26 02:51:03

fluke
Member
From: Shaoguan Univ., PRC
Registered: 2005-08-12
Posts: 241
Website

Re: What's wrong! about MySQL C APIs

Oh, it worked. Thank you!

Offline

Board footer

Powered by FluxBB