Darwin linker error "illegal text-relocation" with -shared

Ryan S. Elliott relliott@umn.edu
Mon Apr 16 19:51:00 GMT 2018


On Mon, 16 Apr 2018, Thomas Koenig wrote:

> OK, so I haven't played around with shared libraries a lot.
>
>> In other words, the -c flag overrides the -shared flag.  This is not what I 
>> want.  I want to create a shared library which is done by the linker.
>
> When I run "gfortran -shared foo.f90" on Linux, I get
>
> /usr/bin/ld: /tmp/ccixEBK9.o: relocation R_X86_64_32 against `.rodata' can 
> not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld: final link failed: Nonrepresentable section on output
> collect2: Fehler: ld gab 1 als Ende-Status zurück
>
> whereas "gfortran -shared -fPIC foo.f90" works.
>
> Is it advisable to compile a shared library without position-independent
> code?
>

No, you are right.   I should have included the -fPIC flag, but this doesn't 
change the results:


$ gfortran-7 -shared -fPIC foo.f90
ld: illegal text-relocation to '_gee' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o from 'lC0' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o for architecture x86_64
collect2: error: ld returned 1 exit status


As indicated in the subject linek, this is only an issue on macOS (Darwin), it 
all works just fine on linux...


Ryan


More information about the Fortran mailing list