dial-reference icon indicating copy to clipboard operation
dial-reference copied to clipboard

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

Open xuwen0306 opened this issue 9 years ago • 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

xuwen0306 avatar Jan 16 '17 06:01 xuwen0306

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 avatar Feb 20 '17 23:02 Artece

@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.

xuwen0306 avatar Feb 21 '17 01:02 xuwen0306