我需要在OS X上爲32位和64位體系結構構建OpenSSL。我需要對./Configure
給出什麼選擇,以便將兩個體系結構構建到同一個.a文件中?在OS X上構建多元OpenSSL
回答
./配置這樣我就可以將它構建到兩個體系結構到相同的.a文件中嗎?
您必須小心OpenSSL和多元庫,因爲庫不是多元安全的。這是因爲每個配置都有自己的<openssl/opensslconf.h>
文件,每個平臺的BIGNUM
都不相同。
由於OpenSSL的構建系統形成命令,供應-arch x86_64 -arch i386
將導致構建失敗。另見Getting libcrypto ar error while compiling OpenSSL for Mac。
以下詳述的相同步驟也適用於iOS。唯一改變的是-arch
。對於iOS,您可能會使用armv7
,armv7s
,arm64
和i386
(用於32位仿真器調試)和x86_64
(用於64位仿真器調試)。
還有另一個不那麼明顯的技巧需要。 OpenSSL硬編碼的一些默認路徑基於--prefix
和--openssldir
,因此您必須爲安裝目錄構建32位,安裝並移動它;然後爲安裝目錄構建64位,安裝,然後移動它;然後在安裝目錄中創建胖庫。另請參閱How to determine the default location for openssl.cnf?
最後,不取代OS X的提供的OpenSSL。 OpenSSL 1.0.x和1.1.x是而不是二進制兼容Apple的0.9.8版本的OpenSSL。由於不兼容,以下程序使用$HOME/ssl
。您可以使用/usr/local/ssl
或任何適合您口味的其他位置。
開始之前,OpenSSL wiki上有一個頁面,其頁面號爲Compilation and Installation。 config
有很多選項可供選擇。選擇適合你口味的。我總是用no-ssl2
,並且通常使用no-ssl3
,no-comp
。在移動設備上,我使用no-srp
,no-psk
,no-hw
,no-dso
和no-engines
。
以下是建立圖書館的說明。您將配置,構建,安裝,然後移動您在多元構建中支持的每個架構。
32位
make clean && make dclean
KERNEL_BITS=32 ./config no-ssl2 no-ssl3 --prefix=$HOME/ssl
make depend
make
make install_sw
mv $HOME/ssl/include/openssl/opensslconf.h $HOME/ssl/include/openssl/opensslconf-x86.h
mv $HOME/ssl/include/openssl/bn.h $HOME/ssl/include/openssl/bn-x86.h
mv $HOME/ssl/ $HOME/ssl-x86
64位
make clean && make dclean
KERNEL_BITS=64 ./config no-ssl2 no-ssl3 --prefix=$HOME/ssl
make depend
make
make install_sw
mv $HOME/ssl/include/openssl/opensslconf.h $HOME/ssl/include/openssl/opensslconf-x64.h
mv $HOME/ssl/include/openssl/bn.h $HOME/ssl/include/openssl/bn-x64.h
mv $HOME/ssl/ $HOME/ssl-x64
頭
你需要複製一個套頭(這並不重要) ,複製opensslconf-x86.h
,opensslconf-x64.h
bn-x86.h
和bn-x64.h
,創建一個新的<openssl/opensslconf.h>
,創建一個新的<openssl/bn.h>
,最後創建多元化庫。
rm -rf $HOME/ssl
mkdir -p $HOME/ssl/bin
mkdir -p $HOME/ssl/include/openssl
mkdir -p $HOME/ssl/lib
cp $HOME/ssl-x86/openssl.cnf $HOME/ssl/openssl.cnf
cp $HOME/ssl-x86/include/openssl/* $HOME/ssl/include/openssl
cp $HOME/ssl-x86/include/openssl/opensslconf-x86.h $HOME/ssl/include/openssl/opensslconf-x86.h
cp $HOME/ssl-x64/include/openssl/opensslconf-x64.h $HOME/ssl/include/openssl/opensslconf-x64.h
cp $HOME/ssl-x86/include/openssl/bn-x86.h $HOME/ssl/include/openssl/bn-x86.h
cp $HOME/ssl-x64/include/openssl/bn-x64.h $HOME/ssl/include/openssl/bn-x64.h
新<opensslconf.h>
如果您還沒有這樣做,創建$HOME/ssl/include/openssl/opensslconf.h
。要確保你使用一個新的頭文件保護(OPENSSL_MULTIARCH_CONF_HEADER
):
cat $HOME/ssl/include/openssl/opensslconf.h
#ifndef OPENSSL_MULTIARCH_CONF_HEADER
#define OPENSSL_MULTIARCH_CONF_HEADER
#if __i386 || __i386__
# include "opensslconf-x86.h"
#elif __x86_64 || __x86_64__ || __amd64 || __amd64__
# include "opensslconf-x64.h"
#else
# error Unknown architecture
#endif
#endif /* OPENSSL_MULTIARCH_CONF_HEADER */
新<bn.h>
創建$HOME/ssl/include/openssl/bn.h
。要確保你使用一個新的頭文件保護(OPENSSL_MULTIARCH_BN_HEADER
):
cat $HOME/ssl/include/openssl/bn.h
#ifndef OPENSSL_MULTIARCH_BN_HEADER
#define OPENSSL_MULTIARCH_BN_HEADER
#if __i386 || __i386__
# include "bn-x86.h"
#elif __x86_64 || __x86_64__ || __amd64 || __amd64__
# include "bn-x64.h"
#else
# error Unknown architecture
#endif
#endif /* OPENSSL_MULTIARCH_BN_HEADER */
庫
在這一點上,你必須位於$HOME/ssl-x86
圖書館的x86版本和位於庫的64位編譯$HOME/ssl-x64
。您將它們與lipo
結合起來,編號爲$HOME/ssl
。
lipo -create $HOME/ssl-x86/lib/libcrypto.a \
$HOME/ssl-x64/lib/libcrypto.a \
-output $HOME/ssl/lib/libcrypto.a
lipo -create $HOME/ssl-x86/lib/libssl.a \
$HOME/ssl-x64/lib/libssl.a \
-output $HOME/ssl/lib/libssl.a
lipo -create $HOME/ssl-x86/bin/openssl \
$HOME/ssl-x64/bin/openssl \
-output $HOME/ssl/bin/openssl
共享庫
如果你shared
配置,那麼你需要執行:
lipo -create $HOME/ssl-x86/lib/libcrypto.1.0.0.dylib \
$HOME/ssl-x64/lib/libcrypto.1.0.0.dylib \
-output $HOME/ssl/lib/libcrypto.1.0.0.dylib
lipo -create $HOME/ssl-x86/lib/libssl.1.0.0.dylib \
$HOME/ssl-x64/lib/libssl.1.0.0.dylib \
-output $HOME/ssl/lib/libssl.1.0.0.dylib
然後,您需要重新創建軟鏈接:
ln -s $HOME/ssl/lib/libcrypto.dylib $HOME/ssl/lib/libcrypto.1.0.0.dylib
ln -s $HOME/ssl/lib/libssl.dylib $HOME/ssl/lib/libssl.1.0.0.dylib
最後,測試一下東西。驗證庫multiarch:
ls $HOME/ssl/lib/
libcrypto.a libssl.a
lipo -info $HOME/ssl/lib/libcrypto.a
Architectures in the fat file: $HOME/ssl/lib/libcrypto.a are: i386 x86_64
lipo -info $HOME/ssl/lib/libssl.a
Architectures in the fat file: $HOME/ssl/lib/libssl.a are: i386 x86_64
然後測試程序:
#include <openssl/opensslconf.h>
#include <openssl/ssl.h>
int main(int argc, char* argv[])
{
SSL_library_init();
return 0;
}
和:
$ clang -arch i386 -arch x86_64 -I $HOME/ssl/include test.c -o test.exe -L $HOME/ssl/lib -lssl -lcrypto
$ DYLD_LIBRARY_PATH=$HOME/ssl/lib; ./test.exe
$
DYLD_LIBRARY_PATH
使用的情況下,你建在OS X的動態庫
如果需要,您可以刪除非multiarch安裝:
rm -rf $HOME/ssl-x86
rm -rf $HOME/ssl-x64
- 1. 在OS X上構建valgrind
- 2. 如何在OS X上指定OpenSSL的構建輸出
- 3. 如何在OS X上使用gcc或clang構建OpenSSL
- 4. 如何在Mac OS X上構建DTrace?
- 5. 在OS X Lion上構建jamvm 1.5.4
- 6. 在Android上構建OpenSSL NDK
- 7. 構建Qt從源頭上OS X 10.10
- 8. 如何從OS X上構建文件?
- 9. 在os x yosemite中更新Openssl
- 10. 建立在XCode 2.5上,OS X 10.4可能與OS X 10.11.3
- 11. 如何在OS X上使用OpenSSL 1.0.1編譯PHP 5.5.19
- 12. 在OS X上更新OpenSSL和自制程序
- 13. 爲什麼需要openssl才能在OS X/Mac OS上運行.NET核心?
- 14. RVM無法在Mountain Lion上構建OpenSSL
- 15. 如何在Android/Linux上構建OpenSSL?
- 16. 科爾多瓦建立在Mac OS X
- 17. 在Mac OS X Lion上構建32位模式Lion
- 18. 在iOS 5和Mac OS X上構建iPhone工具鏈10.7
- 19. 是否可以在Mac OS X上構建FreeGLUT?
- 20. 如何在OS X上爲i386構建ruby 1.8.7?
- 21. 當在OS X上構建GLV時,「OpenGL.h not found」?
- 22. 我無法在os上構建couchbase ruby gem x 10.6.8
- 23. 如何在Mac OS X上構建和使用動態庫?
- 24. 在Mac OS X上使用xampp構建XHP php擴展
- 25. 使用Qt在OS X/Mac上構建C++庫
- 26. MacPorts 1.8.2無法在Mac OS X 1.6.3上構建db46
- 27. 嘗試在os上構建opencv的錯誤x
- 28. mysql-python:在Mac OS X上構建完全獨立的_mysql.so?
- 29. 在Mac OS上構建和安裝Lua 5.2.0 x Lion
- 30. 在Mac OS X上的Android 4.4構建失敗10.9.4
非常感謝。你搖滾! – 2014-09-25 03:53:28