Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: OCI libraries, and PROC

Re: OCI libraries, and PROC

From: ykhogaly <ykhogaly_at_us.oracle.com>
Date: Thu, 23 Dec 1999 21:11:58 -0700
Message-ID: <83uogu$4ib$1@inet16.us.oracle.com>


X. Functionality of the OCI 7.3.x and Pro*C 2.2.x makefiles


  Starting with 7.3, we ship (at least) two makefiles for each product:

  ins_<product>.mk and env_<product>.mk.

  The env makefile just has the macros, and the ins makefile includes the env
  makefile, and has the targets. In the Pro*c case, we have ins_precomp.mk and
  env_precomp.mk. The env_precomp.mk has the necessary macros (such as PROLDLIBS)
  and ins_precomp has the targets to install and relink the precompilers. If
  you look at proc.mk, you can see that it includes env_precomp.mk. So the   idea starting with 7.3 is to just include env_precomp.mk (which is located   under $ORACLE_HOME/precomp) in your own makefile. For people who are using
  the proc.mk makefile without any changes whatsoever, it can be found in   the $ORACLE_HOME/precomp/demo/proc/ directory.

  In order to compile the sample programs (which can be found under the   $ORACLE_HOME/precomp/demo/proc/ directory) using the proc.mk makefile, all you
  need to do is copy the sample program (say sample1.pc) and the proc.mk makefile
  to your own directory and type in the following command:

  make -f proc.mk sample1

  If everything is installed properly the output should be as follows on Solaris
  (the output varies from platform to platform, of course):

  tcsun2% make -f proc.mk sample1
  make -f proc.mk build OBJS=sample1.o EXE=sample1   proc iname=sample1.pc

  Pro*C/C++: Release 2.2.2.0.0 - Production on Sun Dec 15 18:03:11 1996

  Copyright (c) Oracle Corporation 1979, 1994. All rights reserved.

  System default option values taken from:
/u05/oracle/app/oracle/product/7.3.2.2/
  precomp/admin/pcscfg.h

  cc -xO4 -Xc -xstrconst -xcg92 -xF -mr -K PIC -DSLXMX_ENABLE -DSLTS_ENABLE -D_R TRANT -I. -I/u05/oracle/app/oracle/product/7.3.2.2/precomp/public -c sam
  ple1.c
  cc -o sample1
sample1.o -L/u05/oracle/app/oracle/product/7.3.2.2/lib -lclntsh -l

sql -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -lncr -lsql net
  -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3 -lnlsrtl3 -lc ore3 -
  lnlsrtl3 `cat
/u05/oracle/app/oracle/product/7.3.2.2/rdbms/lib/sysliblist`

    -lm -lthread
  tcsun2%

  In order to compile one of your own programs, you would type in the following
  command:

  make -f proc.mk EXE=myprog OBJS=myprog.o

  For example, I have executed the above command by renaming the sample1.pc as
  myprog.pc and here is the output:

  tcsun2% make -f proc.mk EXE=myprog OBJS=myprog.o   proc iname=myprog.pc

  Pro*C/C++: Release 2.2.2.0.0 - Production on Sun Dec 15 18:05:08 1996

  Copyright (c) Oracle Corporation 1979, 1994. All rights reserved.

  System default option values taken from:
/u05/oracle/app/oracle/product/7.3.2.2/
  precomp/admin/pcscfg.h

  cc -xO4 -Xc -xstrconst -xcg92 -xF -mr -K PIC -DSLXMX_ENABLE -DSLTS_ENABLE -D_R TRANT -I. -I/u05/oracle/app/oracle/product/7.3.2.2/precomp/public -c myp
  rog.c
  cc -o myprog
myprog.o -L/u05/oracle/app/oracle/product/7.3.2.2/lib -lclntsh -lsq

l -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -lncr -lsqlne t -l

client -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3 -lnlsrtl3 -lcore3  -ln
  lsrtl3 `cat
/u05/oracle/app/oracle/product/7.3.2.2/rdbms/lib/sysliblist`
  -lm -lthread
  tcsun2%

  Precompiling C++ progams with embedded SQL


  Starting with Pro*C 2.2.x, there are ready made targets for Pro*C++ programs
  which means you don't have to modify your makefiles unless of course the   directory structure for your C++ compiler is different (which is quite   likely).

  Here's the output from compiling the cppdemo1.pc sample program.

  tcsun2% !m
  make -f proc.mk cppdemo1
  make -f proc.mk cppbuild OBJS=cppdemo1.o EXE=cppdemo1   proc code=cpp include=/usr/include
include=/opt/SUNWspro/SC3.0.1/include/CC sys_   include=/SUNWspro/SC4.0/include/CC iname=cppdemo1

  Pro*C/C++: Release 2.2.2.0.0 - Production on Mon Dec 16 12:41:58 1996

  Copyright (c) Oracle Corporation 1979, 1994. All rights reserved.

  System default option values taken from:
/u05/oracle/app/oracle/product/7.3.2.2/
  precomp/admin/pcscfg.h

  CC -c -I. -I/u05/oracle/app/oracle/product/7.3.2.2/precomp/public cppdemo1.c
  CC -o cppdemo1
cppdemo1.o -L/u05/oracle/app/oracle/product/7.3.2.2/lib -lclntsh   -lsql -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -lncr - lsqlne

t -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3 -lnlsrtl3 -lc ore3

   -lnlsrtl3 `cat
/u05/oracle/app/oracle/product/7.3.2.2/rdbms/lib/sysliblist`

      -lm -lthread
  tcsun2%

  Notice that Pro*C 2.2.2 uses the client shared library (libclntsh.so) by default

  which means you do not have to modify your makefile or set any environment   variables to use shared libraries.

  What if you want to compile an OCI program?


  You need to use the oracle.mk makefile which can be found under the   $ORACLE_HOME/rdbms/demo directory. This file includes the env_rdbms.mk   makefile which can be found in the $ORACLE_HOME/rdbms/lib directory.

  tcsun2% make -f oracle.mk cdemo2
  make -f oracle.mk build EXE=cdemo2 OBJS=cdemo2.o   cc -xO4 -Xc -xstrconst -xcg92 -xF -mr -K PIC -DSLXMX_ENABLE -DSLTS_ENABLE -D_R EENTRANT -I/u05/oracle/app/oracle/product/7.3.2.2/rdbms/demo -I/u05/oracle/ app/
  oracle/product/7.3.2.2/rdbms/public -I. -c cdemo2.c   "cdemo2.c", line 189: warning: assignment type mismatch:

          pointer to uchar "=" pointer to char

cc -L/u05/oracle/app/oracle/product/7.3.2.2/lib -L/u05/oracle/app/oracle/pro duct
  /7.3.2.2/rdbms/lib -o cdemo2 cdemo2.o
/u05/oracle/app/oracle/product/7.3.2.2/lib

/libclient.a -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -l
ncr
  -lsqlnet -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3 -lnlsr tl3 -l

core3 -lnlsrtl3 -lsocket -lnsl -lm -ldl -lm -lcore3 -lsocket -lnsl -lm -ldl -R /
  opt/SUNWcluster/lib -Y
P,:/opt/SUNWcluster/lib:/usr/ccs/lib:/usr/lib -Qy -lc /u0   5/oracle/app/oracle/product/7.3.2.2/lib/crtn.o   tcsun2%

  Notice that the above link line does not use shared libraries. In order to
  force the usage of shared libraries, you need to follow a couple of steps   as shown below:

  You can compile the OCI program and force it to use the shared library   (libclntsh.so) using the same oracle.mk makefile with one modification on the
  MAKEDEMO macro line as shown below:

  MAKEDEMO= \

          @if [ "$(ORA_CLIENT_LIB)" = "shared" ]; then \
              $(ECHO) $(CC) -o $(EXE) $(OBJS) $(LIBHOME)/libclntsh.so `cat
$(ORACL
  E_HOME)/rdbms/lib/sysliblist `; \
          else \
              if [ "$(NONDEFER)" = "true" -o "$(NONDEFER)" = "TRUE" ] ; then
\
                  $(ECHO) $(CC) $(LDFLAGS) -o $(EXE) $? $(NDFOPT)
$(OCILDLIBS) $(C
  LIBS); \
          else \
          $(ECHO) $(CC) $(LDFLAGS) -o $(EXE) $? $(OCILDLIBS) $(CLIBS); \
          fi \
        fi


  tcsun2% !m
  make -f oracle.mk cdemo2
  make -f oracle.mk build EXE=cdemo2 OBJS=cdemo2.o   cc -xO4 -Xc -xstrconst -xcg92 -xF -mr -K PIC -DSLXMX_ENABLE -DSLTS_ENABLE -D_R EENTRANT -I/u05/oracle/app/oracle/product/7.3.2.2/rdbms/demo -I/u05/oracle/ app/
  oracle/product/7.3.2.2/rdbms/public -I. -c cdemo2.c   "cdemo2.c", line 189: warning: assignment type mismatch:

          pointer to uchar "=" pointer to char   cc -o cdemo2 cdemo2.o
/u05/oracle/app/oracle/product/7.3.2.2/lib/libclntsh.so -l
  socket -lnsl -lm -ldl
  tcsun2%

  Compiling OCI programs written in C++


  The 7.3.2.x oracle.mk makefile has a ready made target to build OCI programs
  which have C++ style functions in them. Please note that all the C header   files that you include in your C++ OCI programs should be enclosed in an   extern "C" definition as shown below:

  extern "C"
  {

  #include <stdio.h>
  #include <oratypes.h>
  #include <ociapr.h>

  /* demo constants and structs */
  #include <ocidem.h>
  }

  In the $ORACLE_HOME/rdbms/demo directory, cdemo6.cc is an example of a C++   program which accesses the Oracle database. Here is how you would compile   that program.

  tcsun2% make -f oracle.mk cdemo6
  make -f oracle.mk buildc++ EXE=cdemo6 OBJS=cdemo6.o

CC -c -I/u05/oracle/app/oracle/product/7.3.2.2/rdbms/demo -I/u05/oracle/app/ orac
  le/product/7.3.2.2/rdbms/public -I. cdemo6.cc

CC -L/u05/oracle/app/oracle/product/7.3.2.2/lib -L/u05/oracle/app/oracle/pro duct
  /7.3.2.2/rdbms/lib -o cdemo6 cdemo6.o
/u05/oracle/app/oracle/product/7.3.2.2/lib

/libclient.a -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -l
ncr
  -lsqlnet -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6 -lcore3 -lnlsr tl3 -l
  core3 -lnlsrtl3 -lsocket -lnsl -lm -ldl -lm -lcore3   tcsun2%

  Of course, if you want to use the shared library you can do so by modifying your
  oracle.mk makefile as explained earlier.

  New macros worth knowing about in the Pro*C/C++ 2.2 makefile


  PROCFLAGS - what was previously called PROFLAGS   PROCPPFLAGS - macro for C++ programs containing embedded SQL

  Renaming of libraries in OCI makefiles


  If you look through the oracle.mk makefile, you will see some new library   names such as libserver.a and libclient.a. These are nothing but the   libora.a and libocic.a which have been combined with other new libraries   to improve efficiency.

  So here is a mapping between older libraries and their newer counterparts:

  libora.a is replaced by libserver.a   libocic.a is replaced by libclient.a

  Appendix A: Source code for the multiple module example

  Here are the files used in this example:

  extern void sqlerror();
  extern void connect();
  extern void print_names();
  extern void disconnect();

  #include <stdio.h>
  #include "main.h"

  void main() {

    int dept;

    printf("Hello There!\n");

    printf("Now connecting...\n");
    connect("scott", "tiger");

    printf("Enter dept no: ");
    scanf("%d", &dept);

    print_names(dept);

    printf("Disconnecting...\n");
    disconnect();

    }

  #include <stdio.h>
  #include "main.h"
  EXEC SQL include sqlca;

  void connect(username, password)
  char *username;
  char *password; {

    EXEC SQL begin declare section;

      VARCHAR un[20];
      VARCHAR pw[20];

    EXEC SQL end declare section;

    strcpy(un.arr, username);
    un.len = strlen(un.arr);
    strcpy(pw.arr, password);
    pw.len = strlen(pw.arr);

    EXEC SQL whenever sqlerror do sqlerror();

    EXEC SQL connect :un identified by :pw;     }

  void disconnect() {

    EXEC SQL commit work release;
    }

  void sqlerror() {

    printf("SQL error!!\n");
    EXEC SQL whenever sqlerror continue;

    printf("% .70s \n",sqlca.sqlerrm.sqlerrmc);

    EXEC SQL rollback release;
    exit(1);
    }

  #include <stdio.h>
  #include "main.h"
  EXEC SQL include sqlca;

  EXEC SQL begin declare section;
    VARCHAR ename[20];
  EXEC SQL end declare section;

  void print_names(dept)
  EXEC SQL begin declare section;
  int dept;
  EXEC SQL end declare section; {

    EXEC SQL whenever sqlerror do sqlerror();

    EXEC SQL DECLARE emp_cursor CURSOR FOR

      select ename
        from emp
        where deptno = :dept;

    EXEC SQL OPEN emp_cursor;

    EXEC SQL whenever not found goto done_loop;

    printf("Employees in dept %d:\n", dept);

    for (;;) {

      EXEC SQL fetch emp_cursor into :ename;
      ename.arr[ename.len] = '\0';
      printf("%s\n", ename.arr);
      }

    done_loop:
    EXEC SQL CLOSE emp_cursor;
    }

List of useful makefile macros


  Note that many of these macros are defined, but not all of them. proc.mk for Pro*C 2.0, for example, uses PROFLAGS in the precompile targets, but does not
  define it.

  PROFLAGS: options to be passed to the precompiler, such as ireclen or sqlcheck

  CFLAGS:      options to be passed to the compiler, such as -I or -O
  LDFLAGS:     options to be passed to the linker, such as -L
  CC (or RCC): the C compiler (/usr/5bin/cc for Sun)
  PROC:        the precompiler ($ORACLE_HOME/bin/proc)
  LIBHOME:     directory in which to find the Oracle libs ($ORACLE_HOME/lib
for  Oracle7, $ORACLE_HOME/rdbms/lib for version 6)
  LIBxxx:      Oracle library libxxx.a fully qualified (such as LIBSQL,
equal to $(LIBHOME)/libsql.a)
  LLIBxxx:     Oracle library libxxx.a, using -l (such as LLIBCORE, equal
to -lcore)
  PROLDLIBS: Oracle libraries necessary to link (defined in terms of other macros)
  OCILDLIBS: Oracle libraries necessary to link programs using the Oracle Call Interfaces (OCI) (also defined in terms of other macros)

"The Views expressed here are my own and not necessarily those of Oracle Corporation"

<argosy22_at_my-deja.com> wrote in message news:83u5ti$3r3$1_at_nnrp1.deja.com...

> Hi all,
>
> I am used to working in ProC.
> Write embedded SQL in .pc program.
> Pre-compile to .c.
> (the equivilent of an OCI .c)
> Compile .c to .exe.
>
> If a library has been made by OCI,
> for OCI, and is used by OCI programs,
> could it ever be used by a PROC program?
> Of course the makefile would have to
> be modified to point to the compiled library.
>
> I don't expect that it could be, but, I
> thought that I should ask those who
> have experience with the issue.
> (And it's not that I want to, but I had
> a job interview today, where they use OCI,
> even thought they have PROC.)
>
> Merry Christmas,
>
> Argosy
>
>
>
> Sent via Deja.com http://www.deja.com/

> Before you buy.


Received on Thu Dec 23 1999 - 22:11:58 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US