[oracle@Tux10M simpapp]$ gcc fetch.c -I /u01/app/oracle/product/10.2.0/client_1/precomp/public/ -L /u01/app/oracle/product/10.2.0/client_1/lib/ -lclntsh
[oracle@Tux10M simpapp]$ gcc fetch.c -I /u01/app/oracle/product/10.2.0/client_1/precomp/public/ -L /u01/app/oracle/product/10.2.0/client_1/lib/ -lclntsh
fetch.c:148:18: atmi.h: No such file or directory
fetch.c:149:17: fml.h: No such file or directory
fetch.c:150:21: userlog.h: No such file or directory
fetch.c: In function `sql_error':
fetch.c:427: error: 'msg' redeclared as different kind of symbol
fetch.c:426: error: previous definition of 'msg' was here
fetch.c: In function `main':
fetch.c:626: error: request for member `arr' in something not a structure or union
fetch.c:462: warning: return type of 'main' is not `int'
[oracle@Tux10M simpapp]$
都是由于.pc文件的编辑错误引发。
[oracle@Tux10M simpapp]$ cd /u01/app/oracle/product/10.2.0/client_1/precomp/public/
[oracle@Tux10M public]$ pwd
/u01/app/oracle/product/10.2.0/client_1/precomp/public
[oracle@Tux10M public]$
[oracle@Tux10M public]$ ll
total 132
lrwxrwxrwx 1 oracle oinstall 10 Aug 11 2009 BNDDSC.FOR -> bnddsc.for
lrwxrwxrwx 1 oracle oinstall 9 Aug 11 2009 ORACA.COB -> oraca.cob
lrwxrwxrwx 1 oracle oinstall 9 Aug 11 2009 ORACA.FOR -> oraca.for
lrwxrwxrwx 1 oracle oinstall 7 Aug 11 2009 ORACA.H -> oraca.h
lrwxrwxrwx 1 oracle oinstall 10 Aug 11 2009 SELDSC.FOR -> seldsc.for
lrwxrwxrwx 1 oracle oinstall 9 Aug 11 2009 SQLCA.COB -> sqlca.cob
lrwxrwxrwx 1 oracle oinstall 9 Aug 11 2009 SQLCA.FOR -> sqlca.for
lrwxrwxrwx 1 oracle oinstall 7 Aug 11 2009 SQLCA.H -> sqlca.h
lrwxrwxrwx 1 oracle oinstall 7 Aug 11 2009 SQLDA.H -> sqlda.h
-rw-r----- 1 oracle oinstall 11573 Jun 28 2005 bnddsc.for
-rw-r----- 1 oracle oinstall 2673 Jun 28 2005 bndsel.cob
-rw-r----- 1 oracle oinstall 3569 Oct 27 1997 oraca.cbt
-rw-r----- 1 oracle oinstall 5066 Apr 16 1999 oraca.cob
-rw-r----- 1 oracle oinstall 5845 Aug 2 1999 oraca.for
-rw-r----- 1 oracle oinstall 6493 Jun 3 2005 oraca.h
-rw-r----- 1 oracle oinstall 3611 Oct 27 1997 oraca5.cbt
-rw-r----- 1 oracle oinstall 5040 Apr 16 1999 oraca5.cob
-rw-r----- 1 oracle oinstall 10068 Jun 28 2005 seldsc.for
-rw-r----- 1 oracle oinstall 5296 May 8 2002 sql2oci.h
-rw-r----- 1 oracle oinstall 5980 May 8 2002 sqlapr.h
-rw-r----- 1 oracle oinstall 814 Oct 14 1998 sqlca.cbt
-rw-r----- 1 oracle oinstall 2068 Jul 27 1999 sqlca.cob
-rw-r----- 1 oracle oinstall 2290 Jun 28 2005 sqlca.for
-rw-r----- 1 oracle oinstall 3287 Jun 3 2005 sqlca.h
-rw-r----- 1 oracle oinstall 786 Oct 14 1998 sqlca5.cbt
-rw-r----- 1 oracle oinstall 2204 Jul 27 1999 sqlca5.cob
-rw-r----- 1 oracle oinstall 5363 Jun 3 2005 sqlcpr.h
-rw-r----- 1 oracle oinstall 3062 May 8 2002 sqlda.h
-rw-r----- 1 oracle oinstall 6031 May 8 2002 sqlkpr.h
-rw-r----- 1 oracle oinstall 977 Sep 8 2000 sqlucs2.h
[oracle@Tux10M public]$
是说要Include哪些文件吗?
-I 是include哪些头文件,-L是引用哪些库(library)文件.
[oracle@Tux10M simpapp]$ more fetch.pc
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>
#include <atmi.h>
#include <fml.h>
#include <userlog.h>
/* config pro*c operation */
EXEC SQL INCLUDE sqlca;
EXEC SQL INCLUDE oraca;
EXEC ORACLE OPTION(oraca=yes);
/* define constants for varchar length*/
#define UNAME_LEN 20
#define PWD_LENTH 40
/* declare variable, no declare section is needed, if MODE=ORACLE */
VARCHAR username[UNAME_LEN];
varchar password[PWD_LENTH];/*varchar is an oracle-supplied struct, can be lower and upper case*/
/* declare error handling function*/
void sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\n %s \n", msg);
buf_len = sizeof(err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%. *s\n", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
main()
{
EXEC SQL INCLUDE sqlca;
EXEC ORACLE OPTION(RELEASE_CURSOR = YES);
/* register the sql_error() as the error handler*/
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error-- \n");
EXEC SQL BEGIN DECLARE SECTION;
char oraCN[50];
EXEC SQL END DECLARE SECTION;
strcpy(oraCN, "scott/scott@jerry");
EXEC SQL CONNECT raCN;
printf("\n Connected to ORACLE as user: %s \n", oraCN);
/* disconnect from ORACLE*/
EXEC SQL ROLLBACK WORK RELEASE;
return 0;
}
[oracle@Tux10M simpapp]$
[oracle@Tux10M simpapp]$ gcc fetch.c -I /u01/app/oracle/product/10.2.0/client_1/precomp/public/ -I /home/oracle/tux10/include -L /u01/app/oracle/product/10.2.0/client_1/lib/ -lclntsh
Linux添加环境变量与GCC编译器添加INCLUDE与LIB环境变量
对所有用户有效在/etc/profile增加以下内容。只对当前用户有效在Home目录下的
.bashrc或.bash_profile里增加下面的内容:
(注意:等号前面不要加空格,否则可能出现 command not found)
#在PATH中找到可执行文件程序的路径。
export PATH =$PATHHOME/bin
#gcc找到头文件的路径
C_INCLUDE_PATH=/usr/include/libxml2:/MyLib
export C_INCLUDE_PATH
#g++找到头文件的路径
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/libxml2:/MyLib
export CPLUS_INCLUDE_PATH
#找到动态链接库的路径
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/MyLib
export LD_LIBRARY_PATH
#找到静态库的路径
LIBRARY_PATH=$LIBRARY_PATH:/MyLib
export LIBRARY_PATH
--转自