LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-09-2007, 06:14 AM   #1
krisvamc
LQ Newbie
 
Registered: Apr 2007
Posts: 29

Rep: Reputation: 15
Trying to compile simple program, mysql_connect error. anybody help me




Hi,

When I am trying to compile simple TEST.CC program I am getting the mysql_connect error. Can anybody tell what the error is.

The code for test.cc is:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip.h>
#include <sstream>

#include "mysql/mysql.h"
#include "handling.h"
#include "utils.h"
#include "storage.h"
#include "parser.h"
#include "update.h"
#include "unp.h"
#include "readwrite.h"



using namespace std;


MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;

const unsigned ASM_ADDR = 0xe0000000;
const unsigned ASM_MASK = 4;
const unsigned SSM_ADDR = 0xe8000000;
const unsigned SSM_MASK = 8;

bool CreateDatabase() {
//Connection to mysql server
if (mysql_connect(&mysql,NULL,"root","xxxxx") == NULL) {
cout << "Error: Couldn't connect to mysql server.";
return false;
}
cout << "Database created successfully." << endl;
return true;
}


The error is :

root@xxx-laptop:/home/xx/Desktop/xxx# g++ -ansi -pedantic -Wall -W test.cc
In file included from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/iomanip.h:31,
from test.cc:4:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
test.cc: In function ‘bool CreateDatabase()’:
test.cc:31: error: ‘mysql_connect’ was not declared in this scope

root@xxx-laptop:/home/xx/Desktop/xxx#

It tells mysql_connect is not declared in this scope.


thanks.
 
Old 05-09-2007, 06:26 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well you aren't ilnking it to libmysql are you? how is suppopsd to find these libraries? try adding -lmysqlclient. also probably need to define the library directory, -L/usr/local/lib/mysql assuming that is the right location.
 
Old 05-09-2007, 06:30 AM   #3
krisvamc
LQ Newbie
 
Registered: Apr 2007
Posts: 29

Original Poster
Rep: Reputation: 15
Could you please tell in detail how to do this
 
Old 05-09-2007, 06:42 AM   #4
krisvamc
LQ Newbie
 
Registered: Apr 2007
Posts: 29

Original Poster
Rep: Reputation: 15
Even when I tried to compile this with lmysqlclient, again it shows the same error.

g++ -ansi -pedantic -Wall -W -lmysqlclient test.cc
In file included from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/iomanip.h:31,
from test.cc:4:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
test.cc: In function ‘bool CreateDatabase()’:
test.cc:31: error: ‘mysql_connect’ was not declared in this scope
root@xxx-laptop:/home/xxxx/Desktop/xxx#
 
Old 05-09-2007, 06:49 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

The problem is the line
using namespace std;

Here you say you are using the std namespace. The mysql functions are not in that namespace, try to change "mysql_connect" into "::mysql_connect". I guess the functions are in the global namespace.
 
Old 05-09-2007, 07:00 AM   #6
krisvamc
LQ Newbie
 
Registered: Apr 2007
Posts: 29

Original Poster
Rep: Reputation: 15
Even when I changed to "::mysql_connect" again the same error comes.
 
Old 06-20-2007, 06:24 PM   #7
UhhMaybe
Member
 
Registered: Jul 2004
Location: Salt Lake City, Utah
Distribution: Absolute 12.0 Studio 64 1.3.0
Posts: 470

Rep: Reputation: 30
Cool

http://www-ccs.ucsd.edu/c/lib_over.html This will clear up the syntax errors. For the vernacular arguments, try http://www.tldp.org/HOWTO/HOWTO-INDEX/howtos.html
 
  


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
Simple program wont compile BACTRATE Linux - Software 14 07-24-2008 12:57 PM
Simple C program - error with float J_K9 Programming 2 10-24-2005 11:36 AM
A simple program on C++ for the linux with an error. Israfel2000 Programming 4 06-16-2004 06:25 PM
Error for a very simple C program pkashyap Linux - Newbie 2 03-11-2004 10:24 AM
Why doesn't this simple program compile? SparceMatrix Programming 4 08-27-2002 03:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:04 PM.

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