如何使用GCC4.8.5工具链构建libcrypto.so

如何使用GCC4.8.5工具链构建libcrypto.so,gcc,openssl,centos,Gcc,Openssl,Centos,我正在尝试使用GCC4.8.5工具链在CentOS 7上构建libcrypto.so.1.0.0。我得到的错误如下,我不知道该怎么办 /usr/bin/ld:libcrypto.a(e_gost_err.o):创建共享对象时,无法使用针对“.data”的重新定位R_X86_64_32;用-fPIC重新编译 有什么建议吗 [user@rsn-xp openssl-1.0.0s]$ cat /etc/centos-release CentOS Linux release 7.4.1708 (Core

我正在尝试使用GCC4.8.5工具链在CentOS 7上构建libcrypto.so.1.0.0。我得到的错误如下,我不知道该怎么办

/usr/bin/ld:libcrypto.a(e_gost_err.o):创建共享对象时,无法使用针对“.data”的重新定位R_X86_64_32;用-fPIC重新编译

有什么建议吗

[user@rsn-xp openssl-1.0.0s]$ cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

[user@rsn-xp openssl-1.0.0s]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[user@rsn-xp openssl-1.0.0s]$ make libcrypto.so.1.0.0
make[1]: Entering directory `/home/user/src/openssl/openssl-1.0.0s'
make[2]: Entering directory `/home/user/src/openssl/openssl-1.0.0s'
/usr/bin/ld: libcrypto.a(e_gost_err.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
libcrypto.a(e_gost_err.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [link_a.gnu] Error 1
make[2]: Leaving directory `/home/user/src/openssl/openssl-1.0.0s'
make[1]: *** [do_linux-shared] Error 2
make[1]: Leaving directory `/home/user/src/openssl/openssl-1.0.0s'
make: *** [libcrypto.so.1.0.0] Error 2
[user@rsn-xp openssl-1.0.0s]$ 

关于现在要做什么,错误或多或少是清楚的:使用
-fPIC
重新编译。因此,请确保
-fPIC
包含在
CFLAGS
中(例如
CFLAGS=-fPIC make…
)。
潜在的问题是,您(很可能是无意中)尝试混合可重定位代码和不可重定位代码。

奇怪……我检查了makefile中的cflags,并且-fPIC已经存在。因此,我重新编辑了makeclean和make,以确认-fPIC选项已被传入,并且在该选项的基础上,成功构建了.So。我一定是因为某种原因错过了之前的“清理”步骤,导致它从旧的不可重新定位的对象文件中工作。谢谢。将
shared
添加到您的配置标志中。另请参见OpenSSL wiki上的;或者Linux&Unix文件。由于您已经配置/构建了一次,请确保
使distclean
从以前的构建中清除所有工件。