gpt4 book ai didi

macos - 为 Mac 编译 OpenSSL 时出现 libcrypto ar 错误

转载 作者:行者123 更新时间:2023-12-04 23:41:18 27 4
gpt4 key购买 nike

我已经能够为 iOS 设备编译特定版本的 OpenSSL,现在我正在尝试为 Mac OSX 编译。但是,当我运行我的 bash 脚本(如下提供)时,我收到以下错误:

ar  r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format

当我运行 lipo -info libcrypto.a我得到以下结果:
Architectures in the fat file: libcrypto.a are: i386 x86_64 

这没有任何意义,因为我的 bash 脚本只是为 i386 配置 OpenSSL(我一直在循环执行这两项操作,但是一旦我开始遇到这些问题就删除了 x86_64)。

我已尝试遵循类似 SO 问题的答案 herehere .然而,那些产生了相同的结果。此外, OpenSSL Wiki 上的 Mac 安装说明也无济于事。

我的脚本:

构建.sh
projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCHS=("i386")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"

rm -rf openssl* fips*
if [ -d "out" ]; then
rm -rf out
fi

mkdir out
source ./Build-FIPS.sh
cd $projectDir
source ./Build-OpenSSL.sh

构建-OpenSSL.sh
set -e

function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[@]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}

function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}

function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
MACHINE="darwin-i386-cc"
# BSD_ARCH="BSD-generic32"

CONFIG_ARGS="$MACHINE \
$BSD_ARCH \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"

export CC="${GCC} -arch ${BUILD_ARCH}"
export CFLAGS="-isysroot ${SDK_PATH} -I ${projectDir}/out/fips_${BUILD_ARCH}/include"
export LDFLAGS="-arch $BUILD_ARCH"
./Configure ${CONFIG_ARGS}

make depend
make
# make install
# make clean && make dclean
}

main $@

最佳答案

按照@jww 的回答,我发现在主 Makefile(根文件夹中的那个)中更改以下行(第 69 行左右)解决了 ar @jww 提到的链接问题:
AR= ar $(ARFLAGS) rAR= libtool -o
做出这种改变确实让我在这个过程中走得更远。但是,我开始遇到其他问题。进一步的“研究”让我找到了OpenSSL FAQ有一个关于 OpenSSL 无法在 Mac 上构建的问题的页面。它向我指出了 OpenSSL 源代码根目录中的问题文件。那个文件说有一个 MAC ld问题:

This is really a misfeature in ld, which seems to look for .dylib libraries along the whole library path before it bothers looking for .a libraries. This means that -L switches won't matter unless OpenSSL is built with shared library support.

The workaround may be to change the following lines in apps/Makefile and test/Makefile:

LIBCRYPTO=-L.. -lcrypto
LIBSSL=-L.. -lssl

to:

LIBCRYPTO=../libcrypto.a
LIBSSL=../libssl.a



有了这些信息,我为根 Makefile 和 apps 中的 Makefile 创建了一个补丁文件。文件夹。我还发现我必须注释掉主 Makefile 和 apps/Makefile 中的说明。构建 openssl 二进制/可执行文件。仅当您要运行 make install 时才需要这样做。 .

补丁文件与 Build.sh 脚本位于同一级别。在摆弄我的 Build-OpenSSL.sh之后我终于能够为这两个 i386 构建脚本和 x86_64 .

为了将来引用,我包括了两个补丁文件的完整内容,以及下面的两个原始脚本文件。

构建.sh
#!/bin/bash
#

projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

ARCHS=("i386" "x86_64")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"

rm -rf openssl*
if [ -d "out" ]; then
rm -rf out
fi

mkdir out
source ./Build-FIPS.sh
source ./Build-OpenSSL.sh

构建-OpenSSL.sh
#!/bin/bash
#

set -e

function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[@]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}

function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}

function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
if [[ $BUILD_ARCH = "i386" ]]; then
MACHINE="darwin-i386-cc"
NISTP=""
elif [[ $BUILD_ARCH = "x86_64" ]]; then
MACHINE="darwin64-x86_64-cc"
NISTP="enable-ec_nistp_64_gcc_128"
else
exit
fi

CONFIG_ARGS="$MACHINE \
$NISTP \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"

./Configure ${CONFIG_ARGS}

patch Makefile < ../MainMake.patch
patch apps/Makefile < ../AppMake.patch
make depend
make build_libcrypto build_libssl
make install_sw
make clean && make dclean
patch -R Makefile < ../MainMake.patch
patch -R apps/Makefile < ../AppMake.patch
}

main $@

AppMake.patch
--- apps/Makefile   2016-03-01 06:36:53.000000000 -0700
+++ ../Makefile 2016-05-06 13:00:16.000000000 -0600
@@ -26,8 +26,8 @@

DLIBCRYPTO=../libcrypto.a
DLIBSSL=../libssl.a
-LIBCRYPTO=-L.. -lcrypto
-LIBSSL=-L.. -lssl
+LIBCRYPTO=../libcrypto.a
+LIBSSL=../libssl.a

PROGRAM= openssl

@@ -101,24 +101,24 @@
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO

install:
- @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
- @set -e; for i in $(EXE); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
- done;
- @set -e; for i in $(SCRIPTS); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
- done
- @cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
+ # @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
+ # @set -e; for i in $(EXE); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
+ # done;
+ # @set -e; for i in $(SCRIPTS); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
+ # done
+ # @cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf

tags:
ctags $(SRC)

MainMake.patch
--- Makefile    2016-05-06 13:06:11.000000000 -0600
+++ ../Makefile 2016-05-06 13:06:44.000000000 -0600
@@ -602,8 +602,8 @@
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
cp libssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
- cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
- chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
+ # cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
+ # chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc

install_html_docs:
here="`pwd`"; \

关于macos - 为 Mac 编译 OpenSSL 时出现 libcrypto ar 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37063202/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com