Linking with GCC doesn't detect -fPIC flag

516 views Asked by At

I am trying to link some files. Here is my command:

gcc -T linker.ld -o Stack\ Berry.bin -ffreestanding -O2 -nostlib kernel.o boot.o -fPIC -lgcc

How ever, I get this error:

/usr/bin/ld: boot.o: relocation R_X86_64_32 against `.multiboot' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

I have included the -fPIC argument, have I just put it in the wrong place? I have tried putting the argument in where it compiles but no luck. I haven't been able to find any thing for the syntax for this flag. Thanks!

1

There are 1 answers

0
Mike Kinghan On BEST ANSWER

You are passing -fPIC to your linkage command. It is a compiler option, because you need to compile your source code to Position Independent object files.

Remove it from this command and add it to your compilation commands.

(-O2 is likewise a compiler, not linker, option.)