Re: Gcc errors and mysql db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



david wrote:

Hi there,

Im trying to solve this error:
I hav created a web site using html.then I created a database using
mysql.then I proceded to create a CGI using c++.
But fc1 keeps giving me errors as follows:

g++ register_insert.cc
/tmp/cczBekQd.o(.text+0x14): In function
`sql_insert(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const*)':
: undefined reference to `mysql_init'
/tmp/cczBekQd.o(.text+0x37): In function
`sql_insert(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const*)':
: undefined reference to `mysql_real_connect'
/tmp/cczBekQd.o(.text+0xca): In function
`sql_insert(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const*)':
: undefined reference to `mysql_query'
/tmp/cczBekQd.o(.text+0xdf): In function
`sql_insert(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const*)':
: undefined reference to `mysql_affected_rows'
/tmp/cczBekQd.o(.text+0x111): In function
`sql_insert(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const*)':
: undefined reference to `mysql_close'
collect2: ld returned 1 exit status

//Here is my source code:
//are there any namespaces or header files missing???
using namespace std;
#include <mysql/mysql.h>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

void sql_insert (const string dest [])
{
	char *qbuff;
	MYSQL mysql;
	MYSQL_RES* res;
	MYSQL_ROW row;
	mysql_init(&mysql);
	
mysql_real_connect(&mysql,NULL,"root",NULL,"TELECOMMUNICATION",0,0,0);
	qbuff = new char [1024];
	
	sprintf (qbuff,"insert into REGISTER values
('%s','%s','%s','%s','%s')",dest[0].c_str(),dest[1].c_str(),dest[2].c_st
r(),dest[3].c_str(),dest[4].c_str());

		mysql_query(&mysql,qbuff);
		cout << "No of row affected are: "<<
mysql_affected_rows(&mysql);
		mysql_close(&mysql);
}
void replaceAll(string & src, const string & findstr, const string &
replstr) {
			int found = src.find(findstr);
	//size_type found = src.find(findstr);
//size_type gives an error undefined identifier

			while (found != string::npos)
			{
				src.replace(found, findstr.length(),
replstr);
				found = src.find(findstr);
			}
}
void urldecode (string & s)
{
			replaceAll(s, "%2c", ",");
			replaceAll(s, "%0D%0A", "<BR>");
			replaceAll(s, "+", " ");
}
void split (const string & s, char * delim, string dest[])
{
			string temp = s;
			int count = 0;
			char *p;
			//p = strtok(temp.begin(), delim);
			char *a = new char[temp.length()+1];
			strcpy(a,temp.c_str());
			p = strtok(a,delim);
			while(p != NULL)
			{
				dest[count] = p;
				count++;
				p = strtok(0, delim);
			}
			for(int temp=0;temp != count;temp++)
				dest[temp].erase(0,dest[temp].find("=")
+1);
			//delete s[];
}
int main()
{
	string s(getenv("QUERY_STRING"));
	urldecode(s);
	string dest[5];
	split(s,"&",dest);
	sql_insert(dest);
	cout << "content_type:text/html" << endl << endl;
	cout << "<HTML>";
	cout << "<H1>" << "CUSTOMER DETAILS " <<"</H1>";
	cout << "<H4>";
	cout << "<BR> Name : " << dest[0] << "<BR>";
	cout << "<BR> Address : " << dest[1] << "<BR>";
	cout << "<BR> City : " << dest[2] << "<BR>";
	cout << "<BR> Phone: " << dest[3] << "<BR>";
	cout << "<BR> E-mail:" << dest[4] << "<BR>";
	cout << "<TEXTAREA NAME= 'S1' ROW='5' COLS='20'>" <<
dest[0]
	     << endl << dest[1] << endl << dest[2] << endl <<
dest[3]
            << endl << dest[4] << "</TEXTAREA><BR>";
	cout << "<BR>record inserted" << "<BR>";
	cout << "</h4>";
	cout << "</HTML>";
	return 0;
}

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 6/7/2004





Hello

here is a simple example for mysql and c++/c

http://www.hk8.org/old_web/linux/sql/ch13_01.htm

hope this will help

the errors you found are from the linker

check that you don´t forget on compilation -lmysql for the linker

Dirk Wendland

working on :

develop.if2.de



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux