[英]Segmentation fault when Fortran subroutine calls a C program
我有這個大的 Fortran 77 代碼,我正在嘗試編譯和執行。 當我運行可執行文件時,我的程序段錯誤。 該代碼是大約 20 年前編寫的,我使用的是 pgi/2020.4 編譯器。
這是我收到的分段錯誤消息。
程序收到信號 SIGSEGV,分段錯誤。 0x00002aaaac18962d in vfprintf () from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/libc.so.6 缺少單獨的調試信息,使用:debuginfo-安裝 glibc-2.17-325.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64
我已經確定了我的 Fortran 子例程的以下部分的分段錯誤,該子例程調用 C 程序“cfprintf”。
ierr = cfprintf (filefp, string, lens(string))
其中 filefp 是指向位於我的目錄之一中的文件的文件指針,字符串只是 ' ' 並且 lens(string) = 1。程序定義為 POST_UNDERSCORE。
這是cfprintf程序
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#ifdef _CRAY
#ifdef FORTRAN_PASSES_ASSUMED_CHAR_LEN
int CFPRINTF (fileptr, s1, cl1, num_chars)
int *cl1;
#else
int CFPRINTF (fileptr, s1, num_chars)
#endif
#else
#ifdef POST_UNDERSCORE
int cfprintf_ (fileptr, s1, num_chars)
#else
int cfprintf (fileptr, s1, num_chars)
#endif
#endif
/* write num_chars characters from string s1 to file associated with fileptr */
FILE **fileptr;
char *s1;
int *num_chars;
{
char format_string [11];
char buffer[256];
sprintf (format_string, "%c.%ds", '%', *num_chars);
/* write to an intermediate buffer to avoid problems with '\n' */
sprintf (buffer, format_string, s1);
fprintf (*fileptr, "%s\n", buffer);
}
我能做些什么來解決這個問題?
謝謝
舊 fortran 代碼的一個相當常見的問題是使用 32 位值來存儲和處理與 C 端交互的指針。 自然,當編譯為 64 位時,這已經不夠了,並且會出現段錯誤。
您必須挖掘代碼並替換,或者可能擁有預處理器(或其他代碼生成器)可以處理的東西,並使其大小適合目標架構。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.