Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sample C++ Code...Linking error 2

Status
Not open for further replies.

jnalawade

Programmer
Jan 31, 2005
5
US
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
 
Please use the [tt][ignore]
Code:
[/ignore][/tt]
tags when posting code.

> #pragma comment(lib, "d:\\orant\\oci80\\lib\\msvc\\ora803.lib")
Is this how you found it, or is that file really in that location on your system?

--
 
Hi Thanks a lot for the reply..
I have copied the program as it is.
Its not available on my syatem. Shall I remove it?
 
> Shall I remove it?
No, the symbols which are unresolved are most likely resolved by that library (.lib) file.

So you need to obtain it, and update that #pragma to reference the directory where you put that lib file.


--
 
Hi, where can I get this ora803.lib? I don't find it on my local system or linux either.
 
I'm not sure where you'd get it, but I do know it's a file that belongs to Oracle.
Maybe you need to install Oracle to use this program?
 
I searched in Oracle client installation on local machine as well as client installation on Linux machine from where I am executing my sample program. But not found ...Anybody any pointers..
 
I'm confused, are you compiling this on a windows machine or a linux machine?

Some observations
1. #pragma comment(lib, "d:\\orant\\oci80\\lib\\msvc\\ora803.lib")
This is only understood (as far as I know) by Microsoft visual C++ compiler.

2. /usr/bin/ld: Dwarf Error: Invalid or unhandled FORM value: 14.
I think this means that an object file is corrupt, or completely the wrong object format. You might get this for example trying to use the windows .lib file on a linux machine.

Also, what did you type in at the command line to compile this code?
The URL you posted has "How does one compile and link an OCI program?"

--
 
Hi, Thanks for the reply. I have removed line
#pragma comment(lib, "d:\\orant\\oci80\\lib\\msvc\\ora803.lib")
I am compiling it using make file. Now program is working..
I included $(ORAHOME)/rdbms/lib \ to include and link dir path and it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top