Linux で 'C' アプリケーションをコンパイルして実行しようとしていますが、これは Solaris で完全に実行されます。最初に、Solaris でコンパイルされたバイナリ ファイルをコピーして Linux で実行しようとしましたが、cannot execute binary file
. したがって、最初に、Solaris でのコンパイルに使用したのと同じ Makefile を使用して、Linux でコードをコンパイルしようとしました。Makefile の内容は次のとおりです。
PROC=$(ORACLE_HOME)/bin/proc
CFLAGS:=$(CFLAGS) -DSOLARIS
PROCFLAGS:=$(PROCFLAGS) -DSOLARIS
HEADERS= $(HOME)
target = $(HOME)
CC=gcc
%.c :%.ec ; $(PROC) $(PROCFLAGS) \
INCLUDE=/usr/topendurc/inc \
iname=$< oname=$(@F)
%.o :%.c ; $(CC) -I$(HEADERS) -DORA_PROC -c $(CFLAGS) \
-L /usr/local/lib -L ./ -I /usr/local/include $<
MAKEC= mv $(target)/$(@F) $(target)/$(@F).old; \
$(CC) $(CFLAGS) -lnsl -lsocket -lm $^ -L $(target) \
-L $(ORACLE_HOME)/lib -l clntsh \
-o $(target)/$(@F)
$(target)/%:%.o $(CLIBFILES); $(MAKEC)
%:%.o $(CLIBFILES); $(MAKEC)
all: rm_interface clean
rm_interface: lrfunc.o tcp.o trace.o global.o rmi.o license.o purge.o fetch_data.o
clean:
-rm lrfunc.o tcp.o trace.o global.o rmi.o purge.o license.o fetch_data.o trace.c global.c rmi.c
上記の Makefile を使用すると、以下に示すようにコードでエラーが発生しました。
gcc -I/home/dev1o -DORA_PROC -c -DSOLARIS \
-L /usr/local/lib -L ./ -I /usr/local/include global.c
/home/oracle/oracle/product/10.2.0/db_1/bin/proc -DSOLARIS \
INCLUDE=/usr/topendurc/inc \
iname=rmi.ec oname=rmi.c
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Jan 16 13:19:57 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
System default option values taken from: /home/oracle/oracle/product/10.2.0/db_1/precomp/admin/pcscfg.cfg
make: *** [rmi.c] Segmentation fault
make: *** Waiting for unfinished jobs....
global.c: In function `timeout_timer':
global.c:556: error: invalid application of `sizeof' to incomplete type `itimerval'
global.c:558: error: dereferencing pointer to incomplete type
global.c:559: error: dereferencing pointer to incomplete type
global.c:561: error: dereferencing pointer to incomplete type
global.c:562: error: dereferencing pointer to incomplete type
global.c:564: error: `ITIMER_REAL' undeclared (first use in this function)
global.c:564: error: (Each undeclared identifier is reported only once
global.c:564: error: for each function it appears in.)
make: *** [global.o] Error 1
更新:
後で、ファイルにヘッダー ファイルを含めたglobal.ec
ところ、エラーは次のように減少しました。
/home/oracle/oracle/product/10.2.0/db_1/bin/proc -DSOLARIS \
INCLUDE=/usr/topendurc/inc \
iname=global.ec oname=global.c
/home/oracle/oracle/product/10.2.0/db_1/bin/proc -DSOLARIS \
INCLUDE=/usr/topendurc/inc \
iname=rmi.ec oname=rmi.c
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Jan 16 15:05:26 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
System default option values taken from: /home/oracle/oracle/product/10.2.0/db_1/precomp/admin/pcscfg.cfg
make: *** [global.c] Segmentation fault
make: *** Waiting for unfinished jobs....
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Jan 16 15:05:26 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
System default option values taken from: /home/oracle/oracle/product/10.2.0/db_1/precomp/admin/pcscfg.cfg
make: *** [rmi.c] Segmentation fault
注:エラーは .c ファイルで報告されていますが、実際には .ec ファイルです。
global.ec の簡易版
#ifdef ORA_PROC
#include "xxxoracle.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <libgen.h>
#include <string.h>
#include <stropts.h>
#include <sys/time.h>
#include <ctype.h>
#include <signal.h>
#include <unistd.h>
EXEC SQL INCLUDE sqlca;
#define MILLION 1000000
/*connect to oracle database */
int
access_database(void)
{
char str[200]="";
EXEC SQL BEGIN DECLARE SECTION;
char ospasswd = '/';
char dbname[40];
EXEC SQL END DECLARE SECTION;
if (getenv("DBNAME") != 0)
strcpy (dbname, (char *) getenv("DBNAME"));
else
{
trace("Error ENV variable DBNAME not defined");
return(1);
}
#ifdef ORA_PROC
if (strlen(dbname) == strcspn(dbname, "/"))
/* connect to database using Unix/OS password*/
EXEC SQL connect :ospasswd using :dbname;
else
EXEC SQL connect :dbname;
EXEC SQL ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDDHH24MISS';
#endif
if (sqlca.sqlcode)
{
sprintf(str, "access_database(): Error connecting to database\0");
return(1);
}
else
{
sprintf(str, "access_database(): Connecting to database");
}
return(0);
}
誰かがここで同様の質問をし、受け入れられた応答はGNU Autoconfを使用することでした。しかし、私の場合、すべてが Solaris 上で動作しているため、Makefile を変更したり、不足しているヘッダー ファイルを追加したりすることで、動作させることができると思います。また、StackOverflow で同様の投稿を見つけたところ、 GDB のようなデバッガーを使用するよう提案されていました。私の場合、GDB を使用すると役立ちますか?
私はこれに非常に慣れていないので、私を助けてください。