How to compile a ProC program?


I am new im programming with ProC.

I've tried to compile a sample programm from OTN under Linux.

#include <stdlib.h>
#include <stdio.h>
#include "/opt/oracle/precomp/public/sqlca.h"

EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR v_user[40];
    char* connstr = "/";        /* This HAS to be a '/' */
    char* dbalias = "tcp803";   /* This is your SQL*Net Alias */
EXEC SQL END DECLARE SECTION;
 

void sqlerror();
void main()
{
    /* Generic Error Handling */

    EXEC SQL WHENEVER SQLERROR DO sqlerror();
    EXEC SQL WHENEVER SQLWARNING CONTINUE;  /* Generic Code */

    EXEC SQL CONNECT :connstr USING :dbalias;

    EXEC SQL SELECT USER INTO :v_user FROM DUAL;
 
 
printf("%s\n",v_user.arr);
 
 
return;
}
 
 
void
sqlerror()
{
    printf("Stop
Error:\t%i\n",sqlca.sqlcode);
 
exit(1);
}

and then I get the following error messages ..

tarsus:/opt/oracle# gcc -o test proc_sample.c
proc_sample.c:9: parse error before `SQL'
proc_sample.c:9: warning: data definition has no type or storage class
proc_sample.c:10: parse error before `v_user'
proc_sample.c:10: warning: data definition has no type or storage class
proc_sample.c:13: parse error before `SQL'
proc_sample.c:13: warning: data definition has no type or storage class
proc_sample.c: In function `main':
proc_sample.c:21: `EXEC' undeclared (first use this function)
proc_sample.c:21: (Each undeclared identifier is reported only once
proc_sample.c:21: for each function it appears in.)
proc_sample.c:21: parse error before `SQL'
proc_sample.c:28: request for member `arr' in something not a structure
or union

What's wrong ??

Ciao Guddl

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Andreas Gutowski   email: [email protected]   http://www.guddl.de/



Ans:

It sounds like you are trying to compile the embedded SQL code without having
precompiled it.

You would take your code and put it into a .pc file (eg: test.pc).  you turn
this into C code by:

$ proc test.pc

then, you compile the resulting .c file.

The next issue you'll run into is probably:

$ gcc -o test test.c
Undefined                       first referenced
 symbol                             in file
sqlcxt                              /var/tmp/cctPBcf_1.o
ld: fatal: Symbol referencing errors. No output written to test

that will be because you don't have the pro*c libs linked in.

I've found it easiest to just include the sample makefile included in the
precompiler directory and use the symbolic in there to link with.  For example,
by including the proc sample .mk file, I can simply use " -L$(ORACLE_HOME)/lib
$(PROLDLIBS)" in my link line to get the right oracle libs, regardless of
version.

This is a makefile template I use alot.  I set up the symbolics:

TARGET = name of program I want to create  (eg: myprog)
SOURCE = list of .pc files I need to precompile/compile (eg: src1.pc src2.pc)

PROC_ENV_FLAGS = any settings I want to override at make time for ProC
CC_ENV_FLAGS = any setting I want to override at make time for CC

-----------------------------------------------------------------
$(TARGET): $(SOURCE) $(SOURCE:.pc=.c) $(SOURCE:.pc=.o)
    $(CC) $(LDFLAGS) -t -o $(TARGET) \
        $(SOURCE:.pc=.o) -L$(ORACLE_HOME)/lib $(PROLDLIBS)
 
include $(ORACLE_PROC_MAKEFILE)
 
PROCFLAGS= ireclen=255 lines=yes $(PROC_ENV_FLAGS) \
           include=$(ORACLE_HOME)/proc/lib
PROFLAGS=$(PROCFLAGS)
 
CFLAGS=-I. -g $(CC_ENV_FLAGS)
------------------------------------------------------------
With the exception that the makefile has been renamed/moved from version to
version (hence the symbolic ORACLE_PROC_MAKEFILE), this makefile works with 7.x
and 8.x.  The various settings for the oracle_proc_makefile would be:

o70: setenv ORACLE_PROC_MAKEFILE $ORACLE_HOME/proc/demo/proc.mk
o71: setenv ORACLE_PROC_MAKEFILE $ORACLE_HOME/proc/demo/proc.mk
o72: setenv ORACLE_PROC_MAKEFILE $ORACLE_HOME/proc/demo/proc.mk
o73: setenv ORACLE_PROC_MAKEFILE $ORACLE_HOME/precomp/demo/proc/proc.mk
o8 : setenv ORACLE_PROC_MAKEFILE $ORACLE_HOME/precomp/demo/proc/demo_proc.mk
 
 
 
 

Hosted by www.Geocities.ws

1