当前位置: 技术问答>linux和unix
关于linux下和AIX下编译的问题
来源: 互联网 发布时间:2016-03-29
本文导语: 我在linux 下使用可以编译过去,运行起来也一切正常的代码,在AIX下 使用xlc编译就总是出错,而使用cc_r编译的话,编译倒是没有问题,但运行后一些函数返回异常,造成程序崩溃。具体情况如下,请高手指点: 首...
我在linux 下使用可以编译过去,运行起来也一切正常的代码,在AIX下 使用xlc编译就总是出错,而使用cc_r编译的话,编译倒是没有问题,但运行后一些函数返回异常,造成程序崩溃。具体情况如下,请高手指点:
首先是代码:
--------------------------------------------------------------------------------------------------
#include
#include
#include
#include
#include
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR ID[19];
EXEC SQL END DECLARE SECTION;
EXEC ORACLE OPTION (ORACA=YES);
EXEC ORACLE OPTION (RELEASE_CURSOR=YES);
void sql_error()
{
/* This is the Oracle error handler.
* Print diagnostic text containing the error message,
* current SQL statement, and location of error.
*/
printf("n%.*sn",
sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
printf("in "%.*s..."n",
oraca.orastxt.orastxtl, oraca.orastxt.orastxtc);
printf("on line %d of %.*s.nn",
oraca.oraslnr, oraca.orasfnm.orasfnml,
oraca.orasfnm.orasfnmc);
/* Disable Oracle error checking to avoid an infinite loop
* should another error occur within this routine as a
* result of the rollback.
*/
EXEC SQL WHENEVER SQLERROR CONTINUE;
/* Roll back any pending changes and disconnect from Oracle. */
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
int dbConnect(char* username, char* password){
/* Call routine sql_error() if an ORACLE error occurs. */
EXEC SQL WHENEVER SQLERROR DO sql_error();
/* Save text of current SQL statement in the ORACA if an
* error occurs.
*/
oraca.orastxtf = ORASTFERR;
/* Connect to Oracle. */
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL CONNECT :username IDENTIFIED BY :password;
puts("nConnected to ORACLE.n");
return 0;
}
int executeSQL(char* sql){
EXEC SQL EXECUTE IMMEDIATE :sql;
return 0;
}
int commit(){
EXEC SQL COMMIT WORK RELEASE;
return 0;
}
int getID(char* id){
memset((char*)ID.arr, 0, ID.len);
EXEC SQL SELECT getID()
INTO :ID
FROM dual;
ID.arr[ID.len] = '';
strncpy(id, ID.arr, ID.len);
/*id = (char*)strdup((char*)ID.arr);*/
/*printf("ID:%sn", ID.arr);*/
return 0;
}
int main(){
int ret = -1;
char sql[1024];
char id[19];
char *username = "abc";
char *password = "abc";
memset(id, 0, 19);
ret = dbConnect(username, password);
ret = getID(id);
printf("ID:%sn", id);
strcpy((char *)sql, "INSERT INTO OrigReceTab2(MSGID,RECEBNKBIC,OSN,MSGSORT,SENTDT,SENTBNKBIC,SESSIONNO,ISN,RECEDT,PRI,TRAILER,IPTTM) values ('200805301352164611','BKCHCNBJXXX','388213','101',TO_DATE('2008-01-09 01:43:00','YYYY-MM-DD HH24:Mi:SS'),'FRNYUS33XXX','3354','097980',TO_DATE('2008-01-09 14:43:00','YYYY-MM-DD HH24:Mi:SS'),'N','{MAC:989F7473}{CHK:710153F3FB13}{H10801091446}',SYSDATE)");
puts(sql);
ret = executeSQL(sql);
strcpy((char *)sql, "INSERT INTO MSGTAGTAB(TAGID,MSGID,TAG,VLU) values (getID(),'200805301352164611','20','BFSCCN1080108001')");
puts(sql);
ret = executeSQL(sql);
ret = commit();
return 0;
}
--------------------------------------------------------------------------------------------------
这段代码在RHEL下一切正常 proc后的c代码在编译运行后都没什么问题。
但在AIX下编译的时候,
使用xlc编译时总是说上面代码红色部分(strncpy(id, ID.arr, ID.len); )这一句有如下错误:
--------------------------------------------------------
"../db/swiftdb.c", line 544.23: 1506-280 (E) Function argument assignment betwee
n types "const char*" and "unsigned char*" is not allowed.
--------------------------------------------------------
编译选项如下:
========================================================
xlc -L/ora10g/product/10g/rdbms/lib/ -lclntsh -lld -lm `cat /ora10g/product/10g
/rdbms/lib/sysliblist` -lm -lc_r -lpthreads -q64 -qspill=3200 -g -I /usr/inclu
de -I /ora10g/product/10g/rdbms/precomp/public -L/usr/lib -L/itast01/itas/bin/ba
tch
========================================================
而在使用cc_r编译的时候,编译正常,但代码中使用的类似如下的语句
pFirst = (char*)strpbrk(tmp,"#");
if (pFirst == tmp) {
/*printf("t# this is a note...n");*/
}else{
}
时,当tmp首字符为“#”时,进入的却是else的分支。
感觉应该是连接了不同的库函数表现不一样造成的,可就是不知道哪里的问题。请大家指教。
首先是代码:
--------------------------------------------------------------------------------------------------
#include
#include
#include
#include
#include
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR ID[19];
EXEC SQL END DECLARE SECTION;
EXEC ORACLE OPTION (ORACA=YES);
EXEC ORACLE OPTION (RELEASE_CURSOR=YES);
void sql_error()
{
/* This is the Oracle error handler.
* Print diagnostic text containing the error message,
* current SQL statement, and location of error.
*/
printf("n%.*sn",
sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
printf("in "%.*s..."n",
oraca.orastxt.orastxtl, oraca.orastxt.orastxtc);
printf("on line %d of %.*s.nn",
oraca.oraslnr, oraca.orasfnm.orasfnml,
oraca.orasfnm.orasfnmc);
/* Disable Oracle error checking to avoid an infinite loop
* should another error occur within this routine as a
* result of the rollback.
*/
EXEC SQL WHENEVER SQLERROR CONTINUE;
/* Roll back any pending changes and disconnect from Oracle. */
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
int dbConnect(char* username, char* password){
/* Call routine sql_error() if an ORACLE error occurs. */
EXEC SQL WHENEVER SQLERROR DO sql_error();
/* Save text of current SQL statement in the ORACA if an
* error occurs.
*/
oraca.orastxtf = ORASTFERR;
/* Connect to Oracle. */
EXEC ORACLE OPTION (RELEASE_CURSOR = YES);
EXEC SQL CONNECT :username IDENTIFIED BY :password;
puts("nConnected to ORACLE.n");
return 0;
}
int executeSQL(char* sql){
EXEC SQL EXECUTE IMMEDIATE :sql;
return 0;
}
int commit(){
EXEC SQL COMMIT WORK RELEASE;
return 0;
}
int getID(char* id){
memset((char*)ID.arr, 0, ID.len);
EXEC SQL SELECT getID()
INTO :ID
FROM dual;
ID.arr[ID.len] = '';
strncpy(id, ID.arr, ID.len);
/*id = (char*)strdup((char*)ID.arr);*/
/*printf("ID:%sn", ID.arr);*/
return 0;
}
int main(){
int ret = -1;
char sql[1024];
char id[19];
char *username = "abc";
char *password = "abc";
memset(id, 0, 19);
ret = dbConnect(username, password);
ret = getID(id);
printf("ID:%sn", id);
strcpy((char *)sql, "INSERT INTO OrigReceTab2(MSGID,RECEBNKBIC,OSN,MSGSORT,SENTDT,SENTBNKBIC,SESSIONNO,ISN,RECEDT,PRI,TRAILER,IPTTM) values ('200805301352164611','BKCHCNBJXXX','388213','101',TO_DATE('2008-01-09 01:43:00','YYYY-MM-DD HH24:Mi:SS'),'FRNYUS33XXX','3354','097980',TO_DATE('2008-01-09 14:43:00','YYYY-MM-DD HH24:Mi:SS'),'N','{MAC:989F7473}{CHK:710153F3FB13}{H10801091446}',SYSDATE)");
puts(sql);
ret = executeSQL(sql);
strcpy((char *)sql, "INSERT INTO MSGTAGTAB(TAGID,MSGID,TAG,VLU) values (getID(),'200805301352164611','20','BFSCCN1080108001')");
puts(sql);
ret = executeSQL(sql);
ret = commit();
return 0;
}
--------------------------------------------------------------------------------------------------
这段代码在RHEL下一切正常 proc后的c代码在编译运行后都没什么问题。
但在AIX下编译的时候,
使用xlc编译时总是说上面代码红色部分(strncpy(id, ID.arr, ID.len); )这一句有如下错误:
--------------------------------------------------------
"../db/swiftdb.c", line 544.23: 1506-280 (E) Function argument assignment betwee
n types "const char*" and "unsigned char*" is not allowed.
--------------------------------------------------------
编译选项如下:
========================================================
xlc -L/ora10g/product/10g/rdbms/lib/ -lclntsh -lld -lm `cat /ora10g/product/10g
/rdbms/lib/sysliblist` -lm -lc_r -lpthreads -q64 -qspill=3200 -g -I /usr/inclu
de -I /ora10g/product/10g/rdbms/precomp/public -L/usr/lib -L/itast01/itas/bin/ba
tch
========================================================
而在使用cc_r编译的时候,编译正常,但代码中使用的类似如下的语句
pFirst = (char*)strpbrk(tmp,"#");
if (pFirst == tmp) {
/*printf("t# this is a note...n");*/
}else{
}
时,当tmp首字符为“#”时,进入的却是else的分支。
感觉应该是连接了不同的库函数表现不一样造成的,可就是不知道哪里的问题。请大家指教。
|
1、ID.arr是unsigned char*,而strncpy要的是const char*
2、C本身是容许没有函数声明就调用函数的。一般编译器有选项,强制要求所有调用的函数都必须有原型声明。
2、C本身是容许没有函数声明就调用函数的。一般编译器有选项,强制要求所有调用的函数都必须有原型声明。