Home » Developer & Programmer » Precompilers, OCI & OCCI » Not able to compile simple OCI program on linux
Not able to compile simple OCI program on linux [message #584610] Thu, 16 May 2013 03:46
swaorclser
Messages: 56
Registered: August 2011
Member
Hello,

I am trying to run a sample test program on Linux wherein it makes OCI calls as below,

#include <stdio.h>
#include <string.h>
#include "oci.h"
#include "ociapr.h"

void main()
{
  /*
   *  Handles.
   */
  OCIEnv     *envhp;                    /* Environment handle           */
  OCIError   *errhp;                    /* Error handle                 */
  OCIServer  *srvhp;                    /* Server handle                */
  OCISvcCtx  *svchp;                    /* Service context handle       */
  OCISession *usrhp;                    /* Session handle               */

  OCIInitialize((ub4)OCI_DEFAULT,(dvoid *)0,(dvoid * (*)())0,
                (dvoid * (*)())0,(void (*)())0);

  OCIEnvInit((OCIEnv **)&envhp,(ub4)OCI_DEFAULT,(size_t)0,(dvoid **)0);



  OCIHandleAlloc((dvoid *)envhp,(dvoid **)&errhp,(ub4)OCI_HTYPE_ERROR,
                 (size_t)0,(dvoid **)0);

  OCIHandleAlloc((dvoid *)envhp,(dvoid **)&srvhp,(ub4)OCI_HTYPE_SERVER,
                 (size_t)0,(dvoid **)0);


  OCIServerAttach((OCIServer *)srvhp,(OCIError *)errhp,
                                 (text *)0,(sb4)0,(ub4)OCI_DEFAULT);


  OCIHandleAlloc((dvoid *)envhp,(dvoid **)&svchp,(ub4)OCI_HTYPE_SVCCTX,
                 (size_t)0,(dvoid **)0);

  OCIAttrSet((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX,
             (dvoid *)srvhp,(ub4)0,
             (ub4)OCI_ATTR_SERVER,(OCIError *)errhp);

  OCIHandleAlloc((dvoid *)envhp,(dvoid **)&usrhp,(ub4)OCI_HTYPE_SESSION,
                 (size_t)0,(dvoid **)0);

  OCIAttrSet((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION,
             (dvoid *)"scott",(ub4)strlen("scott"),
             (ub4)OCI_ATTR_USERNAME,(OCIError *)errhp);

  OCIAttrSet((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION,
             (dvoid *)"tiger",(ub4)strlen("tiger"),
             (ub4)OCI_ATTR_PASSWORD,(OCIError *)errhp);

  OCISessionBegin((OCISvcCtx *)svchp,(OCIError *)errhp,
                                 (OCISession *)usrhp,
                                 OCI_CRED_RDBMS,OCI_DEFAULT);


  OCIAttrSet((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX,
             (dvoid *)usrhp,(ub4)0,
             (ub4)OCI_ATTR_SESSION,(OCIError *)errhp);

  OCISessionEnd((OCISvcCtx *)svchp,(OCIError *)errhp,
                               (OCISession *)usrhp,(ub4)OCI_DEFAULT);

 OCIServerDetach((OCIServer *)srvhp,(OCIError *)errhp,
                                 (ub4)OCI_DEFAULT);


  OCIHandleFree((dvoid *)srvhp,(ub4)OCI_HTYPE_SERVER);
  OCIHandleFree((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX);
  OCIHandleFree((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION);
  OCIHandleFree((dvoid *)errhp,(ub4)OCI_HTYPE_ERROR);
  OCIHandleFree((dvoid *)envhp,(ub4)OCI_HTYPE_ENV);
}


I edited the demo_rdbms.mk file and it looks like,
NONDEFER=false
DEMO_DIR=$(ORACLE_HOME)/rdbms/demo
DEMO_MAKEFILE = $(DEMO_DIR)/demo_rdbms.mk

generate_sharedlib:
        $(GENCLNTSH)

ocitest: test_oci.o
         gcc test_oci.o -o ocitest

test_oci.o: test_oci.c
         gcc -Wall -c -I/u01/app/oracle/product/11.2.0/db_1/rdbms/lib -I/u01/app/oracle/product/11.2.0/db_1/rdbms/public -L$ORACLE_HOME/lib -lclntsh test_oci.c



When I issue make as below I get errors

Quote:

make -f demo_rdbms.mk ocitest
gcc test_oci.o -o ocitest
test_oci.o: In function `main':
test_oci.c:(.text+0x14e): undefined reference to `OCIInitialize'
test_oci.c:(.text+0x169): undefined reference to `OCIEnvInit'
test_oci.c:(.text+0x1b5): undefined reference to `OCIHandleAlloc'
test_oci.c:(.text+0x1d8): undefined reference to `OCIHandleAlloc'
test_oci.c:(.text+0x224): undefined reference to `OCIServerAttach'
test_oci.c:(.text+0x285): undefined reference to `OCIHandleAlloc'
test_oci.c:(.text+0x2ac): undefined reference to `OCIAttrSet'
test_oci.c:(.text+0x2cf): undefined reference to `OCIHandleAlloc'
test_oci.c:(.text+0x2f7): undefined reference to `OCIAttrSet'
test_oci.c:(.text+0x31f): undefined reference to `OCIAttrSet'
test_oci.c:(.text+0x341): undefined reference to `OCISessionBegin'
test_oci.c:(.text+0x3a6): undefined reference to `OCIAttrSet'
test_oci.c:(.text+0x3c2): undefined reference to `OCISessionEnd'
test_oci.c:(.text+0x418): undefined reference to `OCIServerDetach'
test_oci.c:(.text+0x467): undefined reference to `OCIHandleFree'
test_oci.c:(.text+0x478): undefined reference to `OCIHandleFree'
test_oci.c:(.text+0x489): undefined reference to `OCIHandleFree'
test_oci.c:(.text+0x49a): undefined reference to `OCIHandleFree'
test_oci.c:(.text+0x4ab): undefined reference to `OCIHandleFree'
collect2: ld returned 1 exit status
make: *** [ocitest] Error 1



Please advice.

Thanks n Regards,
swaorclser
Previous Topic: ODCIIndexInsert parameters
Next Topic: analytic functions in Pro*C - rank()
Goto Forum:
  


Current Time: Tue Sep 16 15:15:58 CDT 2014

Total time taken to generate the page: 0.12419 seconds