Article 52B5M undefined reference to variable name `Conn::field'

undefined reference to variable name `Conn::field'

by
rahulvishwakarma
from LinuxQuestions.org on (#52B5M)
hi to all, I've centos 7 and codeblocks 17 in VM. I am trying to build a program in which i am accessing MySQL database from c++ 11 .
In this following program :-

product.h :-
------------
Code:#ifndef PRODUCT_H
#define PRODUCT_H

#include <mysql/my_global.h>
#include <mysql/my_sys.h>
#include <mysql/mysql.h>
#include "draw.h"
#include "stat.h"
class product
{
public:
product();
virtual ~product();
product(const product& other);
product& operator=(const product& other);

void showAllProduct();

void printDashes(MYSQL_RES * resset);
static void printError(MYSQL *conn, char * message);
};

#endif // PRODUCT_Hproduct.cpp:-

Code:#include "product.h"
#include <string>
#include "stat.h"

using std::string;
using std::cout;
using std::cin;
using std::endl;

class Conn;

product::product()
{
//ctor
}

product::~product()
{
//dtor
}

product::product(const product& other)
{
//copy ctor
}

product& product::operator=(const product& rhs)
{
if (this == &rhs) return *this; // handle self assignment
//assignment operator
return *this;
}

void product::printDashes(MYSQL_RES * resset)
{
unsigned int i, j;

mysql_field_seek(resset, 0);
clrscr();
cout << "+";

for(i = 0; i < mysql_num_fields(resset); i++)
{
Conn::field = mysql_fetch_field(resset);
for(j = 0; j < Conn::field->max_length + 2; j++ )
{
cout << "-";
}
cout << "+";
}
cout << endl;
}

void product::showAllProduct()
{

MYSQL * conn = Conn::connection();

cout << " inside show all produucts";
cin.get();
char choose;
clrscr();
drawrect();
int l = 5;
gotoxy(15, 5);

cout << "Welcome To Electronic Store";
cin.get();
gotoxy(15, 6);
cout << "Show All Items Menu";

cin.get();

string strQuery = "select *from tableProductRecords";

cout << strQuery << endl;

int qState = mysql_query(conn, strQuery.c_str());

cout << " before mysql_query " <<endl;

cout << " After qstate " <<endl;
if(qState == 0 )
{
cout << "in side qState " << endl;
Conn::res = mysql_store_result(conn);

cout << "after resuslt set ";

mysql_field_seek(Conn::res, 0);

while((Conn::row = mysql_fetch_row(Conn::res))!= nullptr )
{
printDashes(Conn::res);
}
}
else
{
cout << " error : " << " "<< mysql_errno(conn) << " " << endl;

}
cin.get();
}stat.h is :-

Code:#ifndef STAT_H_INCLUDED
#define STAT_H_INCLUDED

#include <mysql/my_global.h>
#include <mysql/my_sys.h>
#include <mysql/mysql.h>
#include "draw.h"
#include "getchoice.h"
#include "product.h"
#include <iostream>

using std::cout;
using std::endl;

char * menu[] ={
"1. Show All Products",
"2. Add New Product.",
"3. Add New Members.",
"4. View An Existing Product Records.",
"5. View An Existing Member's Record.",
"6. Billing.",
"7. Today's Sail.",
"8. Modify Product Record.",
"9. Modify Member's Record.",
"10. Instructions.",
"11. Exit.",
NULL
};

static char *opt_host = "serverora11gr2.db.net";
static char *opt_user_name = "rahul";
static char *opt_password = "rahul";
static unsigned int opt_port = 3306;
static char *opt_socket_name = NULL;
static char *opt_db_nme = "cbs";
static unsigned int opt_flags = 0;

class Conn
{
public:
static MYSQL *conn, mysql;
static int qstate;
static MYSQL_ROW row;
static MYSQL_RES* res;
static MYSQL_FIELD *field;

static MYSQL* connection();
static void printError(MYSQL *conn, char * message);

};

#endif // STAT_H_INCLUDEDstat.cpp:-
Code:#include "stat.h"

static void printError(MYSQL *conn, char * message)
{
gotoxy(15, 18);
cout << *message;

if(conn != NULL)
{
gotoxy(15, 19);
cout << "Error is : " << mysql_errno(conn) << " " << mysql_sqlstate(conn) << " "<< mysql_error(conn);
}
}

MYSQL * Conn::connection()
{
if(mysql_library_init(0,NULL, NULL))
{
cout << "mysql lib init " << endl;
exit(1);
}

conn = mysql_init(NULL);
if(conn == NULL)
{
cout<< "conn is NULL";
//cin.get();
exit(2);
}

conn = mysql_real_connect (&mysql,"serverora11gr2.db.net","rahul","rahul","cbs",3306,NULL,0);
return conn;
}problem is that it showing following errors :-

Code:-------------- Build: Release in cbs (compiler: GNU GCC Compiler)---------------

g++ -L/usr/lib64/mysql -o bin/Release/cbs obj/Release/draw.o obj/Release/getchoice.o obj/Release/main.o obj/Release/product.o obj/Release/stat.o -s -m64 -lmysqlclient -lmysqlclient_r
obj/Release/product.o:(.data+0x0): multiple definition of `menu'
obj/Release/main.o:(.data+0x0): first defined here
obj/Release/stat.o:(.data+0x0): multiple definition of `menu'
obj/Release/main.o:(.data+0x0): first defined here
obj/Release/product.o: In function `product::printDashes(st_mysql_res*)':
product.cpp:(.text+0xa2): undefined reference to `Conn::field'
product.cpp:(.text+0xc7): undefined reference to `Conn::field'
obj/Release/product.o: In function `product::showAllProduct()':
product.cpp:(.text+0x383): undefined reference to `Conn::res'
product.cpp:(.text+0x38f): undefined reference to `Conn::res'
product.cpp:(.text+0x3a3): undefined reference to `Conn::res'
product.cpp:(.text+0x3b2): undefined reference to `Conn::res'
product.cpp:(.text+0x3c1): undefined reference to `Conn::row'
obj/Release/stat.o: In function `Conn::connection()':
stat.cpp:(.text+0x5): undefined reference to `Conn::mysql'
stat.cpp:(.text+0x2a): undefined reference to `Conn::conn'
stat.cpp:(.text+0x5b): undefined reference to `Conn::mysql'
stat.cpp:(.text+0x67): undefined reference to `Conn::conn'
collect2: error: ld returned 1 exit statushow to recover that.latest?d=yIl2AUoC8zA latest?i=CLx1aZWCjL4:JXNo9G2WsXI:F7zBnMy latest?i=CLx1aZWCjL4:JXNo9G2WsXI:V_sGLiP latest?d=qj6IDK7rITs latest?i=CLx1aZWCjL4:JXNo9G2WsXI:gIN9vFwCLx1aZWCjL4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments