Compile OpenSSL with the 'shared' option?
On CentOS 5.4, OpenSSL compiles fine开发者_高级运维 without 'shared' option. But when I passed that option the compilation fails with:
/usr/bin/ld: libcrypto.a(x86_64-gcc.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
When I try: ./config shared CFLAGS=-fPIC
that doesn't work.
What can I do to get OpenSSL to compile with the 'shared' option?
Thanks
Same problem here, BUT usually Makefiles will consider environment variables for compiler or linker options.
So, if you place the -fPIC
option before calling the configure script, it should take care of it. You can do it with:
CFLAGS=-fPIC ./config shared --prefix=/your/path
or
export CFLAGS=-fPIC
./config shared --prefix=/your/path
It worked for me.
There is an option -fXXX
that you can pass to config so you can do it with:
./config -fPIC shared
Compiling openssl
Download your openssl tarball, unzip, and then ensure that the install directory is named
openssl
.I placed mine in /usr/local/openssl, so I'll use that in my example.
sudo mv openssl-1.0.2u /usr/local/openssl && cd /usr/local/openssl
sudo make distclean
sudo ./config -fPIC -shared
sudo make && sudo install
Now, add the openssl shared library to your PATH.
vim ~/.profile Go export PATH="/usr/local/openssl/lib:$PATH" :wq
Here's how I built OpenSSL with shared libraries. Note that I'm using a cross compiler so I specify things most wouldn't.
# hop into the downloads folder
cd ~/Downloads
# get the branch of openssl you want
git clone -b OpenSSL_1_0_2-stable --single-branch https://github.com/openssl/openssl.git
# make an installation directory
mkdir openssl-install
# go into the cloned openssl directory
cd openssl
# absolute paths needed for the configure
# the "-fPIC -mhard-float" are CFLAGS specific to my project
# the "-shared" is what creates the .so files
# find your desired configuration with `./Configure LIST`
./Configure linux-mips32 --prefix=/home/myusername/Downloads/openssl-install --openssldir=/system/ssl -fPIC -mhard-float -shared
# run the make file (with my specific compiler)
make CC=mips-linux-gnu-gcc RANLIB=mips-linux-gnu-ranlib LD=mips-linux-gnu-ld MAKEDEPPROG=mips-linux-gnu-gcc PROCESSOR=MIPS
The OpenSSL version 1.0 (published today) works fine with the shared option
精彩评论