Netflix/dial-reference

cross compile error "can not be used when making a shared object; recompile with -fPIC"

xuwen0306 opened this issue · 2 comments

  1. Download cross compile gcc from :https://codeload.github.com/offensive-security/gcc-arm-linux-gnueabihf-4.7/zip/master

  2. Modify TARGET in the build.sh in server folder:
    export TARGET=~/Desktop/Del/gcc-arm-linux-gnueabihf-4.7-master/bin/arm-linux-gnueabihf-

  3. execute build.sh
    ~/Desktop/Del/gcc-arm-linux-gnueabihf-4.7-master/bin/arm-linux-gnueabihf-gcc -Wall -Werror -g nf_callbacks.o -o libnfCallbacks.so --shared
    ~/Desktop/Del/gcc-arm-linux-gnueabihf-4.7-master/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: nf_callbacks.o: relocation R_ARM_THM_MOVW_ABS_NC against `spAppNetflix' can not be used when making a shared object; recompile with -fPIC
    nf_callbacks.o: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status
    make: *** [nf_callbacks_lib] Error 1

Search the stackoverflow:
http://stackoverflow.com/questions/13812185/how-to-recompile-with-fpic

even add -fPIC in server/makefile cannnot fix ir:

nf_callbacks_lib: nf_callbacks.o
$(CC) -Wall -Werror -g nf_callbacks.o -o libnfCallbacks.so --shared -fPIC

In server/makefile, adding -fPIC to $(CC) -Wall -g.. works for me:
..
%.o: %.c $(HEADERS)
$(CC) -Wall -g -fPIC -std=gnu99 $(CFLAGS) -c $*.c -o $*.o
..
After all, nf_callbacks.o needs to be compiled with fPIC, not libnfCallbacks.so

@Artece , thanks for the comment. Actually , I tried that way , but still has the same failure.

Finally, I tried to add these module to the Android.mk ( since I have a local Android build environment) , and it worked. So I guess all these error should be related with my cross-compile environment.