tzippy
tzippy

Reputation: 6638

CrossCompile openssl with fPIC compiler flag not working (e_os.h not found)

I ran into trouble when trying to link my project:

arm-linux-gnueabihf/bin/ld: ~/libcrypto_t.a(mem_dbg.o): relocation R_ARM_THM_MOVW_ABS_NC against 'a local symbol' an not be used when making a shared object; recompile with -fPIC
libcrypto_t.a: could not read symbols: Bad value

So I guess I didnt build openssl as shared object. I tired to do so by

export cross=arm-linux-gnueabihf-
    cd openssl-1.0.1e
    ./Configure dist --prefix=$HOME/opensslArm
    make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib" CFLAGS="-fPIC" CXXFLAGS="-fPIC"

But I run into an error right away (IF i leave out the CFLAGS and CXXFLAGS it compiles just fine):

making all in crypto...
make[1]: Entering directory `/home/dev/openssl-1.0.1e/crypto'
( echo "#ifndef MK1MF_BUILD"; \
    echo '  /* auto-generated by crypto/Makefile for crypto/cversion.c */'; \
    echo '  #define CFLAGS "/home/linuxonarm/armv7_devel/dl/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf-gcc -O"'; \
    echo '  #define PLATFORM "dist"'; \
    echo "  #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \
    echo '#endif' ) >buildinf.h
/home/linuxonarm/armv7_devel/dl/gcc-linaro-arm-linux-gnueabihf-4.7-2013.03-20130313_linux/bin/arm-linux-gnueabihf-gcc -fPIC   -c -o cryptlib.o cryptlib.c
In file included from cryptlib.c:117:0:
cryptlib.h:65:18: fatal error: e_os.h: No such file or directory
compilation terminated.
make[1]: *** [cryptlib.o] Error 1
make[1]: Leaving directory `/home/dev/openssl-1.0.1e/crypto'
make: *** [build_crypto] Error 1

Upvotes: 2

Views: 2323

Answers (1)

der_die_das_jojo
der_die_das_jojo

Reputation: 913

You can use this command to add -fPIC CFLAG to the Makefile

./Configure dist -fPIC

and then just call

make CC="${cross}gcc" AR="${cross}ar r" RANLIB="${cross}ranlib"

to compile with the compiler option -fPIC

Upvotes: 1

Related Questions