Thread: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object

Hello.

I want to compile postgresql with this:

./configure --prefix=/opt/postgresql --enable-nls --disable-rpath
--enable-profiling --enable-depend --with-tcl --with-segsize=4
--with-perl --with-python --with-gssapi --with-krb5 --with-pam
--with-ldap --with-ossp-uuid --with-libxml --with-libxslt --with-openssl
--with-zlib --with-gnu-ld
--with-includes="/opt/openssl/include:/opt/libxml2/include:/opt/libxslt/include:/opt/zlib/include:/opt/xz/include"
LDFLAGS="-Wl,-R,ORIGIN/../lib/../lib/../lib../lib:ORIGIN/../lib/x86_64-linux-gnu
-L/opt/openssl/lib -L/opt/libxml2/lib -L/opt/libxslt/lib -L/opt/zlib/lib
-L/opt/xz/lib" LIBS="-llzma -lrt" CPPFLAGS="-I/opt/libxml2/include"

But `make` fails with this error:
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv
-fexcess-precision=standard -pg -DLINUX_PROFILE -pthread  -D_REENTRANT
-D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS -fpic -shared
-Wl,-soname,libpq.so.5 -Wl,--version-script=exports.list -o libpq.so.5.6
fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o
fe-protocol2.o fe-protocol3.o pqexpbuffer.o fe-secure.o libpq-events.o
chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o pqsignal.o thread.o
strlcpy.o getpeereid.o ip.o md5.o encnames.o wchar.o -L../../../src/port
-L../../../src/common
-Wl,-R,ORIGIN/../lib/../lib/../lib../lib:ORIGIN/../lib/x86_64-linux-gnu
-L/opt/openssl/lib -L/opt/libxml2/lib -L/opt/libxslt/lib -L/opt/zlib/lib
-L/opt/xz/lib -L/usr/lib  -Wl,--as-needed  -lssl -lcrypto -lgssapi_krb5
-lcrypt -lldap_r  -lpthread
/usr/bin/ld: /opt/openssl/lib/libssl.a(t1_meth.o): relocation
R_X86_64_32 against `.rodata' can not be used when making a shared
object; recompile with -fPIC
/opt/openssl/lib/libssl.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make[3]: *** [libpq.so.5.6] Error 1
make[3]: Leaving directory
`/home/mimiko/src/postgresql/src/interfaces/libpq'
make[2]: *** [all-libpq-recurse] Error 2
make[2]: Leaving directory `/home/mimiko/src/postgresql/src/interfaces'
make[1]: *** [all-interfaces-recurse] Error 2
make[1]: Leaving directory `/home/mimiko/src/postgresql/src'
make: *** [world-src-recurse] Error 2

Want to mention that openssl, zlib, libxml2, libxslt and xz are compiled
in /opt as static only.

How can I resolve this error, or this is a wrong way?

--
Mimiko desu.


Mimiko <vbvbrj@gmail.com> writes:
> But `make` fails with this error:
> /usr/bin/ld: /opt/openssl/lib/libssl.a(t1_meth.o): relocation
> R_X86_64_32 against `.rodata' can not be used when making a shared
> object; recompile with -fPIC

> Want to mention that openssl, zlib, libxml2, libxslt and xz are compiled
> in /opt as static only.

You cannot use such libraries with Postgres.  They need to be linked with
dynamic shared objects, which means they either need to be DSOs themselves
or at least compiled in a way that would allow them to become part of a
DSO.  As the message says, that means you need to have used -fPIC when
building them (though -fpic might work as well depending on platform).

            regards, tom lane