0

I'm trying to make a dynamic library from source code but getting the following error. I just could not figure out why.

ld: entry.o: relocation R_X86_64_32S against `.text' can not be used when making a shared 
object; recompile with -fPIC
entry.o: error adding symbols: Bad value
Makefile:12: recipe for target 'libdune.so' failed
make: *** [libdune.so] Error 1

I have the source code and my Makefile looks like the following

CC      = gcc
CFLAGS  = -Wall -fPIC -g -O3 -MD
LDFLAGS = -shared
OBJ     = entry.o dune.o vsyscall.o elf.o vm.o util.o page.o procmap.o debug.o apic.o
NOFPU_OBJ = trap.o

$(NOFPU_OBJ): EXTRA_FLAGS := -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -msoft-float

all: libdune.so

libdune.so: $(OBJ) $(NOFPU_OBJ)
        $(LD) -shared -o $(@) $(OBJ) $(NOFPU_OBJ)

clean:
        rm -f *.o test *.d libdune.so

-include *.d

%.o: %.c
        $(CC) $(CFLAGS) $(EXTRA_FLAGS) -o $@ -c $<

“relocation R_X86_64_32S against ” linking Error talks about the almost same problem but in my case, I have the source code that is needed. Any help on how to make it work?

user45698746
  • 305
  • 2
  • 13
  • Just an obvious check: Did you `make clean` before building? If you have a stale `.o` file that wasn't compiled with `-fPIC`, that would cause the problem. – Tom Karzes Nov 13 '20 at 07:11
  • @TomKarzes Yes, I did use make clean before building. And yes, I agree with you that, a file that is not compiled with `-fPIC` would cause a similar problem. However, In `CFLAGS` I specifically use `-fPIC` while compiling. But still getting the error – user45698746 Nov 13 '20 at 08:00
  • That is strange. When you ran `make`, the compilation command for `entry.c` showed the `-fPIC` option right? If so, then I'm not sure what's going on. – Tom Karzes Nov 13 '20 at 08:04
  • @TomKarzes, yes. It Shows this: `gcc -Wall -fPIC -g -O3 -MD -o entry.o -c entry.c` – user45698746 Nov 13 '20 at 08:09
  • Have you tried a simple example, like a single file, just to make sure the basic mechanism is working? If so, then the only other thing I can think of is that there's something unusual in one of the source files (e.g. entry.o) that it doesn't like for some reason. – Tom Karzes Nov 13 '20 at 08:25

0 Answers0