我正在尝试在 Linux 上编译和运行一个在 Solaris 上完美运行的“C”应用程序。我首先尝试只复制在 Solaris 上编译的二进制文件并在 Linux 上运行,但这给了我一个错误,说cannot execute binary file
. 因此,我尝试首先在 Linux 上使用用于在 Solaris 上编译它的相同 Makefile 编译代码。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。但我觉得在我的情况下,Makefile 中的一些更改或通过添加一些丢失的头文件可以使它工作,因为一切都在 Solaris 上工作。我还在 StackOverflow 上找到了类似的帖子,人们建议使用像 GDB 这样的调试器。在我的情况下使用 GDB 会有所帮助吗?
请帮助我,因为我对此很陌生。