簡體   English   中英

如何在Linux上編譯可在Solaris上正常運行的“ C”應用程序?

[英]How to compile a 'C' application on Linux which compiles and runs fine on Solaris?

我正在嘗試在Linux上編譯並運行“ C”應用程序,而該應用程序在Solaris上可以完美運行。 我首先嘗試僅復制在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會有所幫助嗎?

請幫助我,因為我對此很陌生。

使用GDB將無濟於事。 嘗試創建目標文件global.c make過程遇到“分段錯誤”錯誤。 任何*.ec在相同目錄中的文件Makefile將被用來創建一個相應*.c文件通使用的Pro*C工具(由生成文件規定)。 構建rm_interface這一階段肯定失敗了。 最有可能的是, global.c文件未創建或格式錯誤,這意味着您將沒有構建最終可執行文件所需的先決條件,這意味着您無法使用GDB進行調試。 您需要找出為什么Pro*C工具無法使用以下命令從global.ec創建global.cglobal.ec

/home/oracle/oracle/product/10.2.0/db_1/bin/proc  -DSOLARIS \
    INCLUDE=/usr/topendurc/inc \
    iname=global.ec oname=global.c

要對此進行調查,請使用原始問題的注釋中已經列出的建議:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM