2015-11-04 61 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 
相关问题