2015-11-04 142 views
14

我有一個簡單的C程序使用libssl。在OS X上使用libssl編譯C程序El Capitan?

在Linux上,我安裝OpenSSL的-dev軟件包,並與下面的行編譯的程序:

gcc test_libssl.c -o test_libssl -lcrypto -lssl 

現在我想這樣做我的Mac上。在同一行了:

fatal error: 'openssl/conf.h' file not found 

我試圖通過brew install openssl

安裝OpenSSL時(OpenSSL的-dev的沒有工作)與家庭釀造這給了我:

...
==> Installing openssl
==> Downloading https://www.openssl.org/source/openssl-1.0.2a.tar.gz curl: (22) The requested URL returned error: 404 Not Found

我發現了一個related SO question沒有答案。

我也試過

brew info openssl 

,結果被告知,

This formula is keg-only. Mac OS X already provides this software and installing another version in parallel can cause all kinds of trouble.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

我有什麼做/安裝,以便能夠編譯在OS X上使用的libssl-C程序的程序?

或者,第一個地方(給出上面的警告)是一個壞主意嗎?




UPDATE:

我OpenSSL的使用BREW安裝。我不確定這是否是問題,但我更新了釀造。 以釀造的建議

You should probably change the ownership and permissions of /usr/local back to your user account. sudo chown -R $(whoami):admin /usr/local

this問題考慮在內。

然後,以下@Alex雷諾茲的建議,我成功地與

gcc test_libssl.c -o test_libssl -lssl -lcrypto -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include 
+0

它爲過時的理由......你應該在你的應用程序創建OSX特定代碼,使用蘋果的框架(像libcrypto).. 。 – Macmade

+1

@Macmade libcrypto是OpenSSL的一部分。沒有直接相同的本地庫;最接近的等價物(這不是很接近)是CommonCrypto。 – duskwuff

回答

11

我已經家釀上埃爾卡皮坦安裝(10.11.1)編制,並已經安裝OpenSSL的當前版本,沒有明顯的不良影響:

$ uname -a 
Darwin hostname.local 15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64 

$ brew info openssl 
openssl: stable 1.0.2d (bottled) 
OpenSSL SSL/TLS cryptography library 
https://openssl.org/ 

This formula is keg-only. 
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries 

/usr/local/Cellar/openssl/1.0.2d_1 (464 files, 17M) 
    Built from source 
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/openssl.rb 
==> Dependencies 
Build: makedepend ✔ 
==> Options 
--universal 
    Build a universal binary 
--without-check 
    Skip build-time tests (not recommended) 
==> Caveats 
A CA file has been bootstrapped using certificates from the system 
keychain. To add additional certificates, place .pem files in 
    /usr/local/etc/openssl/certs 

and run 
    /usr/local/opt/openssl/bin/c_rehash 

This formula is keg-only, which means it was not symlinked into /usr/local. 

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries 

Generally there are no consequences of this for you. If you build your 
own software and it requires this formula, you'll need to add to your 
build variables: 

    LDFLAGS: -L/usr/local/opt/openssl/lib 
    CPPFLAGS: -I/usr/local/opt/openssl/include 

您是否嘗試過將建議的標誌添加到應用程序的構建語句中?您可以編輯您的應用程序的makefile或其他構建語句,並在brew install openssl之後添加這些條目。這可以幫助您的編譯器查找並鏈接它所需的庫和頭文件。

看起來像一切都在那裏。這裏是頭:

$ ls -al /usr/local/opt/openssl/include/openssl/ 
total 3688 
drwxr-xr-x 77 alexpreynolds admin 2618 Aug 24 13:46 . 
drwxr-xr-x 3 alexpreynolds admin  102 Aug 24 13:46 .. 
-rw-r--r-- 1 alexpreynolds admin 6182 Aug 24 13:46 aes.h 
-rw-r--r-- 1 alexpreynolds admin 63142 Aug 24 13:46 asn1.h 
-rw-r--r-- 1 alexpreynolds admin 24435 Aug 24 13:46 asn1_mac.h 
-rw-r--r-- 1 alexpreynolds admin 34475 Aug 24 13:46 asn1t.h 
-rw-r--r-- 1 alexpreynolds admin 38566 Aug 24 13:46 bio.h 
-rw-r--r-- 1 alexpreynolds admin 5351 Aug 24 13:46 blowfish.h 
... 

以及靜態和動態庫:

$ ls -al /usr/local/opt/openssl/lib 
total 11664 
drwxr-xr-x 10 alexpreynolds admin  340 Aug 24 13:46 . 
drwxr-xr-x 11 alexpreynolds admin  374 Aug 24 13:46 .. 
drwxr-xr-x 14 alexpreynolds admin  476 Aug 24 13:46 engines 
-r--r--r-- 1 alexpreynolds admin 1861780 Aug 24 13:46 libcrypto.1.0.0.dylib 
-r--r--r-- 1 alexpreynolds admin 3206344 Aug 24 13:46 libcrypto.a 
lrwxr-xr-x 1 alexpreynolds admin  21 Aug 24 13:46 libcrypto.dylib -> libcrypto.1.0.0.dylib 
-r--r--r-- 1 alexpreynolds admin 364144 Aug 24 13:46 libssl.1.0.0.dylib 
-r--r--r-- 1 alexpreynolds admin 524424 Aug 24 13:46 libssl.a 
lrwxr-xr-x 1 alexpreynolds admin  18 Aug 24 13:46 libssl.dylib -> libssl.1.0.0.dylib 
drwxr-xr-x 5 alexpreynolds admin  170 Aug 24 13:46 pkgconfig 
相關問題