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

Home -> Community -> Usenet -> c.d.o.server -> Re: How do I compile an OCI program using make?

Re: How do I compile an OCI program using make?

From: Peter Sylvester <not_me_at_not_here.org>
Date: Thu, 20 Apr 2006 16:33:02 -0400
Message-ID: <e28rbj$fii$1@newslocal.mitre.org>


Senator Palpatine wrote:
> I know this topic must have been beaten to death but I am new to OCI
> and Oracle.
> I am converting programs using Sybase DBLIB to Oracle and need to know
> how to
> compile and link. I looked at all the makefiles and they are confusing
> as hell!
> Is there anyone that has a makefile that does a strainght compile and
> link without
> referencing all the other makefiles scattered all over the server?
>
> I have tried to use Pro*Sql to. Here is an example of a makefile I am
> using
> that uses the pre-compiler.
>
> empjob.o: empjob.pc
> $(PROC) $(CSCFLAGS) iname=empjob.pc
> $(CC) $(LDFLAGS) -c empjob.c -I. -I $(INCLUDE) -I $(PCCI)
> $(EXE)
>
> any help would be greatly appreciated.
>
> Thanks!
>
> DS
>

Its been a while since I've used pro*c (8.1.5 or so, mostly Solaris) but here is what I used as a Makefile (note that indented items need a single tab character in front of them):

include ../oracle.make

all: myprogram

clean:

	rm -f *.o count
	../util/rm_generated_files

myprogram: myprogram.o ../util/db_util.o
	@echo building $@ executable ...
	$(CC) $(ORA_LDFLAGS) -o $@ $@.o ../util/db_util.o $(ORA_LIBS)


The file oracle.make is my own and includes definitions for the a lot of platform and version specific stuff that I'm simplifying here, so you will need to do some work on this...

ORA = $(ORACLE_HOME)

ORA_PROC_INC_PATH= INCLUDE=../util
ORA_C_INC_PATH = -I../util
ORA_PROC = $(ORA)/bin/proc
ORA_PROC_FLAGS = LINES=NO $(ORA_PROC_INC_PATH) CODE=ANSI_C
CC=/usr/local/bin/gcc
ORA_CFLAGS = platform_and_version_specific_stuff
ORA_LD_FLAGS = more_platform_and_version_specific_stuff
ORA_LIBS = yet_more_platform_and_version_specific_stuff

.SUFFIXES:
.SUFFIXES: .pc .c .o

# Note: -TMP files cannot be removed without forcing recompiles !

.pc.o:

#	@echo Running Oracle Preprocessor on $*.pc ...
	$(ORA_PROC) $(ORA_PROC_FLAGS) iname=$*.pc
#	@echo Running C compiler on $*.c ...
	$(CC) $(ORA_CFLAGS) -c $*.c
#	mv $*.c $*-TMP.c

.c.o:
#	@echo Running C Compiler on $*.c to create .o file ...
	$(CC) $(ORA_CFLAGS) -c -o $*.o $*.c


You can easily figure out the platform specific stuff by building one of their sample programs and seeing just what options get used.

And here's what the rm_generated_files script looks like (C Shell):

#!/bin/csh
foreach pc_file ( *.pc )

   set c_file = ${pc_file:r}.c
   if ( -e $c_file ) then

     echo removing generated file: $c_file ...
     rm $c_file

   endif
end

Use at your own risk and amusement...

--Peter Received on Thu Apr 20 2006 - 15:33:02 CDT

Original text of this message

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