| View previous topic :: View next topic |
| Author |
Message |
incubator Guru

Joined: 05 Jun 2003 Posts: 584 Location: Belgium
|
Posted: Wed Oct 20, 2004 1:23 pm Post subject: [C/C++] how to compile code that uses oci? |
|
|
I was trying out the example cdemo81.c on oracle's site on using the OCI, since oci.h is located in $ORACLE_HOME/rdbms/public I tried the following:
gcc -I$ORACLE_HOME/rdbms/public cdemo84.c -o cdemo
on the following source
| Code: |
#include <oci.h>
int main(int argc char** argv)
{
OCIEnv *myenvhp; /* the environment handle */
OCIServer *mysrvhp; /* the server handle */
OCIError *myerrhp; /* the error handle */
OCISession *myusrhp; /* user session handle */
OCISvcCtx *mysvchp; /* the service handle */
/* initialize the mode to be the threaded and object environment */
(void) OCIEnvCreate(&myenvhp, OCI_THREADED|OCI_OBJECT, (dvoid *)0,
0, 0, 0, (size_t) 0, (dvoid **)0);
/* allocate a server handle */
(void) OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&mysrvhp,
OCI_HTYPE_SERVER, 0, (dvoid **) 0);
/* allocate an error handle */
(void) OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&myerrhp,
OCI_HTYPE_ERROR, 0, (dvoid **) 0);
/* create a server context */
(void) OCIServerAttach (mysrvhp, myerrhp, (text *)"inst1_alias",
strlen ("inst1_alias"), OCI_DEFAULT);
/* allocate a service handle */
(void) OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&mysvchp,
OCI_HTYPE_SVCCTX, 0, (dvoid **) 0);
/* set the server attribute in the service context handle*/
(void) OCIAttrSet ((dvoid *)mysvchp, OCI_HTYPE_SVCCTX,
(dvoid *)mysrvhp, (ub4) 0, OCI_ATTR_SERVER, myerrhp);
/* allocate a user session handle */
(void) OCIHandleAlloc ((dvoid *)myenvhp, (dvoid **)&myusrhp,
OCI_HTYPE_SESSION, 0, (dvoid **) 0);
/* set user name attribute in user session handle */
(void) OCIAttrSet ((dvoid *)myusrhp, OCI_HTYPE_SESSION,
(dvoid *)"hr", (ub4)strlen("hr"),
OCI_ATTR_USERNAME, myerrhp);
/* set password attribute in user session handle */
(void) OCIAttrSet ((dvoid *)myusrhp, OCI_HTYPE_SESSION,
(dvoid *)"hr", (ub4)strlen("hr"),
OCI_ATTR_PASSWORD, myerrhp);
(void) OCISessionBegin ((dvoid *) mysvchp, myerrhp, myusrhp,
OCI_CRED_RDBMS, OCI_DEFAULT);
/* set the user session attribute in the service context handle*/
(void) OCIAttrSet ( (dvoid *)mysvchp, OCI_HTYPE_SVCCTX,
(dvoid *)myusrhp, (ub4) 0, OCI_ATTR_SESSION, myerrhp);
} |
but I keep getting errors of undefined things
gcc -I$ORACLE_HOME/rdbms/public cdemo.c -o cdemo/tmp/cctGHNbp.o(.text+0x4f): In function `main':
: undefined reference to `OCIEnvCreate'
/tmp/cctGHNbp.o(.text+0x79): In function `main':
: undefined reference to `OCIHandleAlloc'
/tmp/cctGHNbp.o(.text+0xa3): In function `main':
: undefined reference to `OCIHandleAlloc'
/tmp/cctGHNbp.o(.text+0xcd): In function `main':
: undefined reference to `OCIServerAttach'
/tmp/cctGHNbp.o(.text+0xf7): In function `main':
: undefined reference to `OCIHandleAlloc'
/tmp/cctGHNbp.o(.text+0x128): In function `main':
: undefined reference to `OCIAttrSet'
/tmp/cctGHNbp.o(.text+0x152): In function `main':
: undefined reference to `OCIHandleAlloc'
/tmp/cctGHNbp.o(.text+0x184): In function `main':
: undefined reference to `OCIAttrSet'
/tmp/cctGHNbp.o(.text+0x1b6): In function `main':
: undefined reference to `OCIAttrSet'
i DOnt know wich lib to add to gcc nor wether to use -L or -l or where its located  |
|
| Back to top |
|
 |
hecatomb Guru


Joined: 02 Sep 2004 Posts: 525
|
Posted: Wed Oct 20, 2004 2:24 pm Post subject: |
|
|
Haven't used OCI yet but should be the "same" as everywhere!
| Quote: | | gcc -I$ORACLE_HOME/rdbms/public cdemo84.c -o cdemo |
You specified -I to add to the paths where the compiler searches for header files.
If you want to add a path to the lib-search path try -L.
| Code: | | gcc -I$ORACLE_HOME/rdbms/public -L$ORACLE_HOME/lib cdemo84.c -o cdemo |
To link the correct library to your object you have to specify it using -l.
| Code: | | gcc -I$ORACLE_HOME/rdbms/public -L$ORACLE_HOME/lib cdemo84.c -o cdemo -loci |
For more informations: http://www.adp-gmbh.ch/ora/misc/oci/ |
|
| Back to top |
|
 |
incubator Guru

Joined: 05 Jun 2003 Posts: 584 Location: Belgium
|
Posted: Wed Oct 20, 2004 2:38 pm Post subject: |
|
|
thanks, that was just the thing i needed  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|