LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-24-2002, 05:36 PM   #1
f0d
LQ Newbie
 
Registered: Feb 2002
Distribution: Slackware 7.0
Posts: 9

Rep: Reputation: 0
C++ and mysql problem. please help


hi,
i'm trying to interface with a mysql db from C++ and I'm getting weird compilation errors. i'm running Slackware7.0.
this is the program:
code:

Code:
#include <mysql/mysql.h>
#include <stdio.h> #define host "127.0.0.1"
#define username "root"
#define password ""
#define db "ccnums" int main()
{
MYSQL *conn;
conn = mysql_init(NULL);
mysql_real_connect(conn, host, username, password, db, 0, NULL, 0);

MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i;

mysql_query(conn, "select * from nums");
res_set = mysql_store_result(conn);

unsigned int numrows = mysql_num_rows(res_set);
while((row = mysql_fetch_row(res_set)) != NULL)
{
for (i=0; i<mysql_num_fields(res_set); i++)
printf("%s\n", row[i] != NULL ? row[i] : "NULL");
}

mysql_close(conn);
return 0;
}

and the errors:
Code:
code: /tmp/ccVA60Wf.o: In function `main':
/tmp/ccVA60Wf.o(.text+0xc): undefined reference to `mysql_init'
/tmp/ccVA60Wf.o(.text+0x37): undefined reference to `mysql_real_connect'
/tmp/ccVA60Wf.o(.text+0x4b): undefined reference to `mysql_query'
/tmp/ccVA60Wf.o(.text+0x5a): undefined reference to `mysql_store_result'
/tmp/ccVA60Wf.o(.text+0x6e): undefined reference to `mysql_num_rows'
/tmp/ccVA60Wf.o(.text+0x88): undefined reference to `mysql_fetch_row'
/tmp/ccVA60Wf.o(.text+0xaf): undefined reference to `mysql_num_fields'
/tmp/ccVA60Wf.o(.text+0x10d): undefined reference to `mysql_close'
collect2: ld returned 1 exit status
i'd appreciate it if someone would clear this up for me.
Martin
 
Old 02-24-2002, 09:06 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Your link step is failing. The linker can't find the mysql client library. Add a -lmysqlclient to your compile.

Code:
gcc -g -omyprog myprov.cpp -lmysqlclient
 
Old 02-25-2002, 02:27 PM   #3
f0d
LQ Newbie
 
Registered: Feb 2002
Distribution: Slackware 7.0
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks alot man, worked like a dream.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bugzilla - MySQL - perl - DBD::mysql install problem Runningonair Linux - Software 8 10-12-2007 12:42 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
mysql 4.0.24 to mysql 4.1.12 upgrade problem tuxrules Slackware 7 08-13-2005 06:43 PM
MySQL server problem after linking (mysql.sock) ewijaya Linux - General 4 01-19-2004 09:46 AM
MySQL mysql-3.23.56-1.9, rpm install problem jacsmith510 Linux - Newbie 3 09-19-2003 02:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration