Oracle Database Development (4). Example Makefile for Pro*C
<本文主要介绍Linux下使用Makefile编译ProC程序的方法>
It is a pity that there is a few aritcle written in Chinese which talking about
the material method of Makefile for Pro*C/C++ .Maybe it's not diffcult to the most
Linux developers , but I find lots of questions about the method of compile
which follows no answer .
the material method of Makefile for Pro*C/C++ .Maybe it's not diffcult to the most
Linux developers , but I find lots of questions about the method of compile
which follows no answer .
I don't know why .
1.Preface
Assumed that you just finished the installation of Oracle Pro*C In Linux OS ,
you hurry to enter the directory which contains lots of Pro*C examples and type
this command " make -f demo_proc.mk sample1 " to get a first programme. In all
probability you could find lots of errors and warnings full of the screen instead
of a imaged executable file.
Don't worry , let us discover the secrect in it , which is the mainly content
of this artical.
you hurry to enter the directory which contains lots of Pro*C examples and type
this command " make -f demo_proc.mk sample1 " to get a first programme. In all
probability you could find lots of errors and warnings full of the screen instead
of a imaged executable file.
Don't worry , let us discover the secrect in it , which is the mainly content
of this artical.
Oracle DataBase Development Series
http://blog.csdn.net/liwei_cmg/category/207442.aspx
http://blog.csdn.net/liwei_cmg/category/207442.aspx
2.The causation of errors
In the beginning , I was also puzzled with this errors , for i had no idea with
Precompiler Options . Everything becomes clear go with the knowing the Precompiler
Options.
Input your command " proc parse=? " at the command line .
$ proc parse=?
You should see the prompt following .
Pro*C/C++: Release 9.2.0.4.0 - Production on Fri Jun 8 12:22:36 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
Option name : parse=string
Current value : full
Restrictions : full, partial, none
Description : Control which non-SQL code is parsed
PCC-F-02135, CMD-LINE: User asked for help
Precompiler Options . Everything becomes clear go with the knowing the Precompiler
Options.
Input your command " proc parse=? " at the command line .
$ proc parse=?
You should see the prompt following .
Pro*C/C++: Release 9.2.0.4.0 - Production on Fri Jun 8 12:22:36 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
Option name : parse=string
Current value : full
Restrictions : full, partial, none
Description : Control which non-SQL code is parsed
PCC-F-02135, CMD-LINE: User asked for help
Check the makefile named "demo_proc.mk" and the predefined environment file
named "env_precomp.mk" , and you will find the variable $(PROCFLAGS) not defined .
Oralce used the default value when compiled the sample. According to last article
《Oracle Database Development (3). Introduce to Pro*C/C++ Precompiler Options》,
we know that we should set the value of SYS_INCLUDE option. Just follow the
instruction , you would get a better result .
The key step of the compilers listed on the sceen is perhaps like this :
proc iname=sample1 include=. include=/home/ora/ora9/oracle/precomp/public include=/home/ora/ora9/oracle/rdbms/public include=/home/ora/ora9/oracle/rdbms/demo include=/home/ora/ora9/oracle/plsql/public include=/home/ora/ora9/oracle/network/public
named "env_precomp.mk" , and you will find the variable $(PROCFLAGS) not defined .
Oralce used the default value when compiled the sample. According to last article
《Oracle Database Development (3). Introduce to Pro*C/C++ Precompiler Options》,
we know that we should set the value of SYS_INCLUDE option. Just follow the
instruction , you would get a better result .
The key step of the compilers listed on the sceen is perhaps like this :
proc iname=sample1 include=. include=/home/ora/ora9/oracle/precomp/public include=/home/ora/ora9/oracle/rdbms/public include=/home/ora/ora9/oracle/rdbms/demo include=/home/ora/ora9/oracle/plsql/public include=/home/ora/ora9/oracle/network/public
/usr/bin/gcc -O3 -trigraphs -fPIC -DPRECOMP -I. -I/home/ora/ora9/oracle/precomp/public -I/home/ora/ora9/oracle/rdbms/public -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/plsql/public -I/home/ora/ora9/oracle/network/public -DLINUX -D_GNU_SOURCE -D_LARGEFILE64_SOURCE=1 -D_LARGEFILE_SOURCE=1 -DSLTS_ENABLE -DSLMXMX_ENABLE -D_REENTRANT -DNS_THREADS -c sample1.c
sample1.c: In function `main':
sample1.c:241: warning: return type of `main' is not `int'
/usr/bin/gcc -o sample1 sample1.o -L/home/ora/ora9/oracle/lib/ -lclntsh `cat /home/ora/ora9/oracle/lib/ldflags` `cat /home/ora/ora9/oracle/lib/sysliblist` -ldl -lm
sample1.o(.text+0x3b6): In function `main':
: the `gets' function is dangerous and should not be used.
Some warnings comes again , i don't mind , for we have already known what it is !
sample1.c: In function `main':
sample1.c:241: warning: return type of `main' is not `int'
/usr/bin/gcc -o sample1 sample1.o -L/home/ora/ora9/oracle/lib/ -lclntsh `cat /home/ora/ora9/oracle/lib/ldflags` `cat /home/ora/ora9/oracle/lib/sysliblist` -ldl -lm
sample1.o(.text+0x3b6): In function `main':
: the `gets' function is dangerous and should not be used.
Some warnings comes again , i don't mind , for we have already known what it is !
3.Using Oracle defined Makefile
Here is the detail below.
Copy the file "demo_proc.mk" to your own directory and rename it by yourself .
The source file " main.pc " , which have the same content with the example mentioned
before , is created then .
[ora@liwei src]$ ls
main.pc proc.mk
Add the "-lclntsh" to the file "$ORACLE_HOME/lib/sysliblist" .
[ora@liwei lib]$ cat sysliblist
-lclntsh -ldl -lm -lpthread -lnsl -lirc
Start to compile .
[ora@liwei src]$ make -f proc.mk main
make -f /home/ora/ora9/oracle/precomp/demo/proc/demo_proc.mk PROCFLAGS="" PCCSRC=main I_SYM=include= pc1
make[1]: Entering directory `/home/ora/develop/src'
proc iname=main include=. include=/home/ora/ora9/oracle/precomp/public include=/home/ora/ora9/oracle/rdbms/public include=/home/ora/ora9/oracle/rdbms/demo include=/home/ora/ora9/oracle/plsql/public include=/home/ora/ora9/oracle/network/public
Pro*C/C++: Release 9.2.0.4.0 - Production on Fri Jun 8 16:18:20 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
make[1]: Leaving directory `/home/ora/develop/src'
/usr/bin/gcc -O3 -trigraphs -fPIC -DPRECOMP -I. -I/home/ora/ora9/oracle/precomp/public -I/home/ora/ora9/oracle/rdbms/public -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/plsql/public -I/home/ora/ora9/oracle/network/public -DLINUX -D_GNU_SOURCE -D_LARGEFILE64_SOURCE=1 -D_LARGEFILE_SOURCE=1 -DSLTS_ENABLE -DSLMXMX_ENABLE -D_REENTRANT -DNS_THREADS -c main.c
/usr/bin/gcc -o main -L/home/ora/ora9/oracle/precomp/lib/ -L/home/ora/ora9/oracle/lib/ -L/home/ora/ora9/oracle/lib/stubs/ main.o `cat /home/ora/ora9/oracle/lib/sysliblist` -ldl -lm -o main
rm main.o
Everything is OK now.
Copy the file "demo_proc.mk" to your own directory and rename it by yourself .
The source file " main.pc " , which have the same content with the example mentioned
before , is created then .
[ora@liwei src]$ ls
main.pc proc.mk
Add the "-lclntsh" to the file "$ORACLE_HOME/lib/sysliblist" .
[ora@liwei lib]$ cat sysliblist
-lclntsh -ldl -lm -lpthread -lnsl -lirc
Start to compile .
[ora@liwei src]$ make -f proc.mk main
make -f /home/ora/ora9/oracle/precomp/demo/proc/demo_proc.mk PROCFLAGS="" PCCSRC=main I_SYM=include= pc1
make[1]: Entering directory `/home/ora/develop/src'
proc iname=main include=. include=/home/ora/ora9/oracle/precomp/public include=/home/ora/ora9/oracle/rdbms/public include=/home/ora/ora9/oracle/rdbms/demo include=/home/ora/ora9/oracle/plsql/public include=/home/ora/ora9/oracle/network/public
Pro*C/C++: Release 9.2.0.4.0 - Production on Fri Jun 8 16:18:20 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
System default option values taken from: /home/ora/ora9/oracle/precomp/admin/pcscfg.cfg
make[1]: Leaving directory `/home/ora/develop/src'
/usr/bin/gcc -O3 -trigraphs -fPIC -DPRECOMP -I. -I/home/ora/ora9/oracle/precomp/public -I/home/ora/ora9/oracle/rdbms/public -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/plsql/public -I/home/ora/ora9/oracle/network/public -DLINUX -D_GNU_SOURCE -D_LARGEFILE64_SOURCE=1 -D_LARGEFILE_SOURCE=1 -DSLTS_ENABLE -DSLMXMX_ENABLE -D_REENTRANT -DNS_THREADS -c main.c
/usr/bin/gcc -o main -L/home/ora/ora9/oracle/precomp/lib/ -L/home/ora/ora9/oracle/lib/ -L/home/ora/ora9/oracle/lib/stubs/ main.o `cat /home/ora/ora9/oracle/lib/sysliblist` -ldl -lm -o main
rm main.o
Everything is OK now.
4.Make your own Makefile
The Makefile defined by Oracle can compile any Pro*C/C++ file . Someone may
prefer to make a new one by themselves, which is more simple .
Due to the existence of the powerfull Oracle Makefile , it becomes a piece of cake .
Let me list the content of a simple file .
[ora@liwei src]$
[ora@liwei src]$ pwd
/home/ora/develop/src
[ora@liwei src]$ ls
Makefile main.pc proc.mk
[ora@liwei src]$ cat Makefile
include $(ORACLE_HOME)/precomp/lib/env_precomp.mk
# PROC, CFLAGS, LDPATHFLAG, LIBHOME, PROLDLIBS are defined in env_precomp.mk
# Redhat Linux
CC=/usr/bin/gcc
build: $(OBJS)
$(DEMO_PROC_BUILD_SHARED)
main:
$(MAKE) -f Makefile OBJS=$@.o EXE=$@ build
clean:
rm main *.o *.lis *.c
.SUFFIXES: .pc .c .o
.pc.c:
$(PROC) $(PROCFLAGS) iname=$*
.pc.o:
$(PROC) $(PROCFLAGS) iname=$*
$(C2O)
.c.o:
$(C2O)
The statement "$(MAKE) -f Makefile OBJS=$@.o EXE=$@ build" could be considerd
a entrance of the complier . $@ actually means "main" in this sentence.
The target 'build' puts together an executable $(EXE) from the .o files in
$(OBJS) and the libraries in $(PROLDLIBS). You can get the following message
if your find it in "env_precomp.mk"
DEMO_PROC_BUILD_SHARED_32=$(CC) $(LFLAGS32) -o $(EXE) $(OBJS) $(LDPATHFLAG)$(LIBHOME) $(PROLDLIBS)
Search the key word "Makefile" in Google for more details about it.
$ make clean
$ make main
Note: "make main" equals "make -f Makefile main".
5.Postscript
you to automagically build and manage your projects.
Most of the Windows developers strange with the theory of Makefile ,for Windows
IDE have nearly done every work at the aspect of compile . The Makefile is known
as nmake in VC IDE . Every developer , i think , should know the theory more or
less .