在OS X El Capitan上使用libssl编译C程序? [英] Compiling C programs using libssl on OS X El Capitan?

查看:250
本文介绍了在OS X El Capitan上使用libssl编译C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的使用libssl的C程序。



在Linux上,我安装了openssl-dev软件包并使用以下行编译程序:

  gcc test_libssl.c -o test_libssl -lcrypto -lssl 

现在我想在我的Mac上也做同样的事情。同一行导致:

 致命错误:'openssl / conf.h'文件未找到

我试着通过 brew install openssl来安装openssl(openssl-dev不起作用)


$ b

这给了我:


... < br>
==>安装openssl

==>正在下载 https://www.openssl.org/source/openssl-1.0.2a.tar.gz
curl:(22)请求的网址返回错误:404未找到
p>

我找到了相关的SO问题,没有答案。



我也试过了

  brew info openssl 

并得知


此公式仅限桶。
Mac OS X已经提供了这个软件,并且在
并行版本中安装另一个版本可能会导致各种麻烦。



Apple已弃用OpenSSL对自己的TLS和加密库的青睐

为了能够编译libssl-using C,我必须做些什么/安装程序在OS X上的程序?



或者,第一个地方(给出上面的警告)是不是一个好主意?









更新:

使用brew安装openssl。我不确定这是否是问题,但我更新了酿造。
采取brew的建议


您应该将/ usr / local
的所有权和权限更改回您的用户帐户。
sudo chown -R $(whoami):admin / usr / local

和<一个href =https://github.com/Homebrew/homebrew/issues/44973 =noreferrer>这个问题。



然后,遵循@Alex Reynolds的建议,我成功地将它编译为

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


解决方案

我在El Capitan(10.11.1)上安装了Homebrew,并且安装了当前版本的OpenSSL,没有明显的不良影响:

  $ uname -a 
Darwin hostname.local 15.0.0 Darwin内核版本15.0.0:Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11〜1 / RELEASE_X86_64 x86_64

$ brew信息openssl
openssl:stable 1.0.2d(瓶装)
OpenSSL SSL / TLS加密库
https://openssl.org/

这个公式只有桶。
Apple不赞成使用OpenSSL来支持自己的TLS和加密库

/usr/local/Cellar/openssl/1.0.2d_1(464个文件,17M)
建立源码
来自:https://github.com/Homebrew/homebrew/blob/master/Library/Formula/openssl.rb
==>依赖项
构建:makedepend✔
==>选项
--universal
构建通用二进制文件
--without-check
跳过构建时测试(不推荐)
==>警告
CA文件已使用系统
钥匙串中的证书进行引导。要添加额外的证书,请将.pem文件放在
/ usr / local / etc / openssl / certs

中,并运行
/ usr / local / opt / openssl / bin / c_rehash

这个公式只有桶,这意味着它没有符号链接到/ usr / local。

Apple不赞成使用OpenSSL来支持自己的TLS和加密库

通常这对你没有任何影响。如果你构建你的
自己的软件,并且需要这个公式,你需要添加到你的
构建变量中:

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 
总计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引擎
-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


I have a simple C program using libssl.

On Linux, I installed the openssl-dev package and compiled the program with the following line:

gcc test_libssl.c -o test_libssl -lcrypto -lssl

Now I would like to do the same on my Mac. The same line resulted in:

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

I tried installing openssl (openssl-dev did not work) with home-brew via brew install openssl

This gave me:

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

I found a related SO question with no answer.

I also tried

brew info openssl

and got informed that

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

What do I have to do / install in order to be able to compile libssl-using C programs programs on OS X?

Or, is it a bad idea the first place (given the warning above)?




UPDATE:

I got the openssl installed using brew. I am not sure if this was the problem but I updated brew. Taking brew's advice

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

and this issue into account.

Then, following @Alex Reynolds's advice, I compiled it successfully with

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

解决方案

I have Homebrew installed on El Capitan (10.11.1) and have installed a current version of OpenSSL with no apparent ill effects:

$ 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

Have you tried adding the flags that it suggests to your app's build statement? You might edit your app's makefile or other build statement and add those entries, after a brew install openssl. This may help your compiler find and link the library and header files it needs.

Looks like everything is there. Here are headers:

$ 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
...

And static and dynamic libraries:

$ 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

这篇关于在OS X El Capitan上使用libssl编译C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆