Hi, I have sample c++ code with make file. I want to add one more functionality to the same. I am not c++ programmer. I got one source code from net at But this program has main function. I renamed it as one of class from existing code has main function. Now I want to call this new funstion from one of my existing class.
So I created .h file as,
==========================================================
#ifndef __TEST_SAMPLE_H__
#define __TEST_SAMPLE_H__
#include <oci.h>
static OCIEnv *p_env;
static OCIError *p_err;
static OCISvcCtx *p_svc;
static OCIStmt *p_sql;
static OCIDefine *p_dfn = (OCIDefine *) 0;
static OCIBind *p_bnd = (OCIBind *) 0;
class Test_Sample
{
public:
static void Test_Sample::insert_smfusnd2();
private:
};
#endif // _CONFIG_H
==========================================================
My .cc file is
==========================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oci.h>
#include <Test_Sample.h>
#pragma comment(lib, "d:\\orant\\oci80\\lib\\msvc\\ora803.lib")
void Test_Sample::insert_smfusnd2()
{
int p_bvi;
char p_sli[20];
int rc;
char errbuf[100];
int errcode;
rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0, /* Initialize OCI */
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 );
/* Initialize evironment */
rc = OCIEnvInit( (OCIEnv **) &p_env, OCI_DEFAULT, (size_t) 0, (dvoid **) 0 );
/* Initialize handles */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_err, OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0);
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_svc, OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0);
/* Connect to database server */
rc = OCILogon(p_env, p_err, &p_svc, (OraText *) "FUSION", 6, (OraText *) "fusion", 6, (OraText *) "SMFUSND2", 8);
if (rc != 0) {
OCIErrorGet((dvoid *)p_err, (ub4) 1, (text *) NULL, &errcode, (OraText *) errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
printf("Error - %.*s\n", 512, errbuf);
exit(8);
}
/* Allocate and prepare SQL statement */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql,
OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
rc = OCIStmtPrepare(p_sql, p_err, (OraText *) "select ename from emp where deptno=:x", (ub4) 37, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
/* Bind the values for the bind variables */
p_bvi = 10; /* Use DEPTNO=10 */
rc = OCIBindByName(p_sql, &p_bnd, p_err, (text *) ":x",
-1, (dvoid *) &p_bvi, sizeof(int), SQLT_INT, (dvoid *) 0,
(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
/* Define the select list items */
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 1, (dvoid *) &p_sli,
(sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT);
/* Execute the SQL statment */
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0,
(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
while (rc != OCI_NO_DATA) { /* Fetch the remaining data */
printf("%s\n",p_sli);
rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
}
rc = OCILogoff(p_svc, p_err); /* Disconnect */
rc = OCIHandleFree((dvoid *) p_sql, OCI_HTYPE_STMT); /* Free handles */
rc = OCIHandleFree((dvoid *) p_svc, OCI_HTYPE_SVCCTX);
rc = OCIHandleFree((dvoid *) p_err, OCI_HTYPE_ERROR);
}
==========================================================
But while linking it gives error as
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
Test_Sample.o: In function `Test_Sample::insert_smfusnd2()':
:17: undefined reference to `OCIInitialize'
:23: undefined reference to `OCIEnvInit'
:26: undefined reference to `OCIHandleAlloc'
:27: undefined reference to `OCIHandleAlloc'
:30: undefined reference to `OCILogon'
:32: undefined reference to `OCIErrorGet'
:38: undefined reference to `OCIHandleAlloc'
:40: undefined reference to `OCIStmtPrepare'
:44: undefined reference to `OCIBindByName'
:49: undefined reference to `OCIDefineByPos'
:54: undefined reference to `OCIStmtExecute'
:59: undefined reference to `OCIStmtFetch'
:62: undefined reference to `OCILogoff'
:63: undefined reference to `OCIHandleFree'
:64: undefined reference to `OCIHandleFree'
:65: undefined reference to `OCIHandleFree'
What can be the error...Can anybody help me to correct this...? Your help in this regard will be highly appreciated..
Thanks,
Jitendra
So I created .h file as,
==========================================================
#ifndef __TEST_SAMPLE_H__
#define __TEST_SAMPLE_H__
#include <oci.h>
static OCIEnv *p_env;
static OCIError *p_err;
static OCISvcCtx *p_svc;
static OCIStmt *p_sql;
static OCIDefine *p_dfn = (OCIDefine *) 0;
static OCIBind *p_bnd = (OCIBind *) 0;
class Test_Sample
{
public:
static void Test_Sample::insert_smfusnd2();
private:
};
#endif // _CONFIG_H
==========================================================
My .cc file is
==========================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oci.h>
#include <Test_Sample.h>
#pragma comment(lib, "d:\\orant\\oci80\\lib\\msvc\\ora803.lib")
void Test_Sample::insert_smfusnd2()
{
int p_bvi;
char p_sli[20];
int rc;
char errbuf[100];
int errcode;
rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0, /* Initialize OCI */
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 );
/* Initialize evironment */
rc = OCIEnvInit( (OCIEnv **) &p_env, OCI_DEFAULT, (size_t) 0, (dvoid **) 0 );
/* Initialize handles */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_err, OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0);
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_svc, OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0);
/* Connect to database server */
rc = OCILogon(p_env, p_err, &p_svc, (OraText *) "FUSION", 6, (OraText *) "fusion", 6, (OraText *) "SMFUSND2", 8);
if (rc != 0) {
OCIErrorGet((dvoid *)p_err, (ub4) 1, (text *) NULL, &errcode, (OraText *) errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR);
printf("Error - %.*s\n", 512, errbuf);
exit(8);
}
/* Allocate and prepare SQL statement */
rc = OCIHandleAlloc( (dvoid *) p_env, (dvoid **) &p_sql,
OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0);
rc = OCIStmtPrepare(p_sql, p_err, (OraText *) "select ename from emp where deptno=:x", (ub4) 37, (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT);
/* Bind the values for the bind variables */
p_bvi = 10; /* Use DEPTNO=10 */
rc = OCIBindByName(p_sql, &p_bnd, p_err, (text *) ":x",
-1, (dvoid *) &p_bvi, sizeof(int), SQLT_INT, (dvoid *) 0,
(ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
/* Define the select list items */
rc = OCIDefineByPos(p_sql, &p_dfn, p_err, 1, (dvoid *) &p_sli,
(sword) 20, SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT);
/* Execute the SQL statment */
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4) 1, (ub4) 0,
(CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT);
while (rc != OCI_NO_DATA) { /* Fetch the remaining data */
printf("%s\n",p_sli);
rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
}
rc = OCILogoff(p_svc, p_err); /* Disconnect */
rc = OCIHandleFree((dvoid *) p_sql, OCI_HTYPE_STMT); /* Free handles */
rc = OCIHandleFree((dvoid *) p_svc, OCI_HTYPE_SVCCTX);
rc = OCIHandleFree((dvoid *) p_err, OCI_HTYPE_ERROR);
}
==========================================================
But while linking it gives error as
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
/usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
Test_Sample.o: In function `Test_Sample::insert_smfusnd2()':
:17: undefined reference to `OCIInitialize'
:23: undefined reference to `OCIEnvInit'
:26: undefined reference to `OCIHandleAlloc'
:27: undefined reference to `OCIHandleAlloc'
:30: undefined reference to `OCILogon'
:32: undefined reference to `OCIErrorGet'
:38: undefined reference to `OCIHandleAlloc'
:40: undefined reference to `OCIStmtPrepare'
:44: undefined reference to `OCIBindByName'
:49: undefined reference to `OCIDefineByPos'
:54: undefined reference to `OCIStmtExecute'
:59: undefined reference to `OCIStmtFetch'
:62: undefined reference to `OCILogoff'
:63: undefined reference to `OCIHandleFree'
:64: undefined reference to `OCIHandleFree'
:65: undefined reference to `OCIHandleFree'
What can be the error...Can anybody help me to correct this...? Your help in this regard will be highly appreciated..
Thanks,
Jitendra