【问题标题】:Compile OpenSSL with the 'shared' option?使用“共享”选项编译 OpenSSL?
【发布时间】:2011-02-01 23:54:50
【问题描述】:

在 CentOS 5.4 上,OpenSSL 在没有“共享”选项的情况下可以正常编译。但是当我通过该选项时,编译失败:

/usr/bin/ld: libcrypto.a(x86_64-gcc.o): 重定位 R_X86_64_32 反对 `a local symbol' 在制作共享对象时不能使用;用 -fPIC 重新编译

当我尝试时:./config shared CFLAGS=-fPIC 不起作用。

如何让 OpenSSL 使用“共享”选项进行编译?

谢谢

【问题讨论】:

  • 您是否在不共享运行和共享运行之间“清理”了?这是什么 OpenSSL 版本?

标签: apache openssl


【解决方案1】:

同样的问题,但通常 Makefile 会考虑编译器或链接器选项的环境变量。

因此,如果您在调用配置脚本之前放置-fPIC 选项,它应该会处理它。你可以这样做:

CFLAGS=-fPIC ./config shared --prefix=/your/path

export CFLAGS=-fPIC
./config shared --prefix=/your/path

它对我有用。

【讨论】:

  • +1 - 今天在一个完全不同的项目中遇到了这个,并且可以确认它完美地工作。如果您已经尝试在没有此正确命令行的情况下构建它,请记住make clean
【解决方案2】:

有一个选项-fXXX,您可以将其传递给配置,以便您可以使用:

./config -fPIC shared

【讨论】:

  • 如果您之前尝试过构建,请务必在添加 -fPIC 之前“清理”。
  • 他们需要一个 2KLOC Perl 脚本来组合一些命令行选项,而且他们甚至无法在可能是最流行的平台(Linux x64)上正确使用它。我敢肯定这里的某个地方有教训。
  • 是的,它被称为像其他人一样使用 GNU autoconf!
  • 我只是获得了 -fPIC 标志,认为我没有添加共享部分。它自己的 -fPIC 似乎没有做任何事情,因此请确保您还添加了 shared。
【解决方案3】:

编译openssl

下载您的 openssl 压缩包,解压缩,然后确保安装目录名为 openssl

我将我的放在 /usr/local/openssl 中,所以我将在我的示例中使用它。

  1. sudo mv openssl-1.0.2u /usr/local/openssl && cd /usr/local/openssl

  2. sudo make distclean

  3. sudo ./config -fPIC -shared

  4. sudo make && sudo install

    现在,将 openssl 共享库添加到您的 PATH。

  5. vim ~/.profile Go export PATH="/usr/local/openssl/lib:$PATH" :wq

【讨论】:

    【解决方案4】:

    以下是我使用共享库构建 OpenSSL 的方法。请注意,我使用的是交叉编译器,因此我指定了大多数不会指定的内容。

    # 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
    

    【讨论】:

    • 你用的是什么ndk版本
    【解决方案5】:

    OpenSSL 1.0 版(今天发布)与共享选项配合良好

    【讨论】:

    • 好吧,我在 1.0.0j 上仍有同样的问题
    • @arved 在带有 CMake v2.8 的 Ubuntu 16.04.1 LTS x64 上确认:使用 -fPIC shared 抱怨 libcrypto.a 不是使用 -fPIC 构建的。
    猜你喜欢
    • 2019-03-26
    • 2018-04-09
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多