【问题标题】:Fortran relocation truncated to fit - mcmodel -fPIC not working [duplicate]Fortran 重定位被截断以适应 - mcmodel -fPIC 不工作 [重复]
【发布时间】:2019-11-18 20:02:02
【问题描述】:

我附上的makefile来自一个平滑粒子流体动力学代码的源目录。当我将粒子数固定为 128**3 个粒子时,我的代码编译得很好。现在我需要使用 256**3 我得到一个relocation truncated to fit: R_X86_64_PC32 against symbol ... defined in COMMON section in ...

我已经尝试了一些我在网上找到的东西:

  • 使用 set stacksize unlimited 命令
  • 添加-mcmodel=large 标志
  • 添加-fPIC 标志

这些似乎都不起作用。我也知道https://www.technovelty.org/c/relocation-truncated-to-fit-wtf.html 的文章,但我不明白我应该做什么。

我的makefile:(我附上一部分)

include ../makeflags
CPP=g++  
CPPFLAGS = $(OPTIONS) -D$(SYS) -mcmodel=large -traceback

.SUFFIXES: .F

OBJ = hydra.o accel.o ahtime.o clist.o cool.o createcool.o dumpdata.o   

.f.o:
    $(F77) $(FLAGS) -c $<
.F.o:
    @ if test $(SYS) = ibm ; then \
    echo "$(CPP) -P -C $(CPPFLAGS) $< > tmp/$*.f";\
    $(CPP) -P -C $(CPPFLAGS) $< > tmp/$*.f;\
    echo "$(F77) $(FLAGS) -c tmp/$*.f";\
    $(F77) $(FLAGS) -c tmp/$*.f;\
        elif test $(SYS) = f2c ; then \
        echo "$(CPP) -P -C $(CPPFLAGS) $< > tmp/$*.f";\
        $(CPP) -P -C $(CPPFLAGS) $< > tmp/$*.f;\
        echo "$(F77) $(FLAGS) -c tmp/$*.f";\
        $(F77) $(FLAGS) -c tmp/$*.f;\
    else \
    echo "$(F77) $(FLAGS) $(CPPFLAGS) -c $<";\
    $(F77) $(FLAGS) $(CPPFLAGS) -c $<;\
    fi

.c.o:
    $(CC) -c $(CPPFLAGS) $(CFLAGS) $<

hydra:  tmp $(OBJ) 
    echo $(FLAGS) 
    $(F77) -o hydra $(FLAGS) $(OBJ) $(LIBS)
    mv hydra $(RUNDIR)

new_options:
    touch *.F
    make

clean:
    /bin/rm  -rf *.o tmp 

system.o: system.$(SYS)
    @ if test $(SYS) = f2c ; then \
    cp system.f2c system.c; \
    $(CC) -c $(CPPFLAGS) $(CFLAGS) system.c; \
    else \
    cp system.$(SYS) system.f; \
    $(F77) $(FLAGS) -c system.f; \
    fi

tmp:    
    @ test -d $@ || mkdir $@
    @ for i in `ls *.inc` ; do \
    (cd tmp ; ln -s ../$$i $$i ) ; \
    done

我的标志文件:(我附上一部分)

SHELL = /bin/sh

# set SYS to one of: sun, dec, cray, sgi, ibm, hpux, f2c, g77
SYS = g77

# choose appropriate names for compilers
F77 = /usr/bin/f77
CC = cc
CPP = /lib/cpp 

# compilation flags for linux box
FLAGS= -O2
FLAGS=  -O2 -fomit-frame-pointer -m486 
FLAGS= -Wall -g 
FLAGS= -mcmodel=large

# For cosmic test use
  UNITS_OPTIONS =
  OTHER_OPTIONS =

OPTIONS = $(FORCE_OPTIONS) $(UNITS_OPTIONS) $(OTHER_OPTIONS)

我知道这是一些内存问题,由于某种原因,我上面描述的选项无法解决这个问题。请记住,我不能弄乱代码中的变量定义(例如更改 COMMON 块等),因为它们链接到许多程序,这将导致编译的整体失败。我收到的确切错误是:

/home/user/Downloads/Stage/hydra4.0/src/hydra.F:1:(.text+0x14):重定位被截断以适应:R_X86_64_PC32 针对 hydra.o 中 COMMON 部分中定义的符号“param_”

对于许多组件程序,不仅仅是hydra.o

【问题讨论】:

标签: fortran relocation


【解决方案1】:

在研究了这个问题 3 个月后,我通过添加 -mcmodel=medium 解决了它。

【讨论】:

  • 其中一个原因可能是您甚至没有告诉我们您使用的是哪个 Fortran 编译器。我们本可以为您指出 stackoverflow.com/questions/32174313/… 之类的内容
  • g77 如我最初的帖子中所述。
  • 我不相信 g77 有 -Mlarge_arrays 标志。如果你打电话给/usr/bin/f77,那么它可以是任何东西。
  • 我刚才注意到 -Mlarge_arrays 没有被我的编译器考虑在内。所以 -mcmodel=medium 完成了所有工作。
猜你喜欢
  • 2013-12-25
  • 1970-01-01
  • 2016-05-01
  • 2016-04-03
  • 2018-04-06
  • 2020-05-23
  • 2015-10-20
  • 1970-01-01
相关资源
最近更新 更多