如何将 OpenSSL 添加到 Xcode 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33341113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:06:34  来源:igfitidea点击:

How to add OpenSSL to an Xcode project

xcodemacosopenssl

提问by Baruch

I am trying to port an application to mac OSX. It uses openssl. I am new to xcode and mac development. Do I need to compile and install openssl myself, or is there some equivalent of an openssl-devel package available as part of the OS or with homebrew or some such?

我正在尝试将应用程序移植到 mac OSX。它使用openssl。我是 xcode 和 mac 开发的新手。我是否需要自己编译和安装 openssl,或者是否有一些等效的 openssl-devel 软件包可作为操作系统的一部分或自制软件或类似软件提供?

采纳答案by DarkDust

You will need to compile and link it yourself, and your app needs to ship it. If the license of your app and OpenSSL's license are compatible, you may use static linking. Otherwise you will need to dynamically link it.

你需要自己编译和链接它,你的应用程序需要发布它。如果您的应用程序的许可证和 OpenSSL 的许可证兼容,您可以使用静态链接。否则,您将需要动态链接它。

There are a few documents describing the processand build scriptsthat you can find with Google searches. For iOS, there's even a Github project. I didn't copy the contents of those documents here since it's too much and it's a moving target.

您可以通过 Google 搜索找到一些描述过程构建脚本的文档。对于 iOS,甚至还有一个Github 项目。我没有在这里复制这些文件的内容,因为它太多了,而且是一个移动的目标。

You can also install OpenSSL with Homebrew. If you just want to have your app run on your Mac and you don't want to distribute it, this is the easiest way: you just need to link it. But if you want to distribute your app, you would need to copy the library/libraries to your app bundle and make sure the the linker finds it there. This also has the disadvantage that there's a possible "disconnect" between your app and the OpenSSL version: if in one year, you update OpenSSL with Homebrew and want to compile/link an older version of your app against the very same OpenSSL version as you've used at that time, you have a problem.

您还可以使用 Homebrew 安装 OpenSSL。如果您只想让您的应用程序在您的 Mac 上运行而您不想分发它,这是最简单的方法:您只需要链接它。但是如果你想分发你的应用程序,你需要将库/库复制到你的应用程序包并确保链接器在那里找到它。这也有一个缺点,即您的应用程序和 OpenSSL 版本之间可能存在“断开连接”:如果在一年内,您使用 Homebrew 更新 OpenSSL 并希望针对与您完全相同的 OpenSSL 版本编译/链接旧版本的应用程序那个时候用过,你有问题。

回答by annoying_squid

  1. Download source from openssl source.
  2. Extract compressed file into directory of your choice. .
  3. Open command line and go to that directory and type something similar to ./configure darwin64-x86_64-cc.
  4. Then type make depend.
  5. Then make install.
  6. Go to your Xcode project build settings. Under Header Search Paths add /usr/local/ssl/includeand library search paths /usr/local/ssl/lib(or whatever install paths you chose in the configure step) .
  7. Still in build settings go to Linking and under other linker flags put -lssl -lcrypto
  1. openssl source下载源代码
  2. 将压缩文件解压缩到您选择的目录中。.
  3. 打开命令行并转到该目录并键入类似于./configure darwin64-x86_64-cc.
  4. 然后键入make depend
  5. 然后make install
  6. 转到您的 Xcode 项目构建设置。在标题搜索路径下添加/usr/local/ssl/include和库搜索路径/usr/local/ssl/lib(或您在配置步骤中选择的任何安装路径)。
  7. 仍在构建设置中转到链接并在其他链接器标志下放置 -lssl -lcrypto

You should be good to go now.

你现在应该可以走了。

回答by Drl Sherif Omran

i tried today starting of 2020

我今天尝试从 2020 年开始

install openssl with homebrew

使用自制软件安装 openssl

brew install openssl

this will install openssl version 1.1d in

这将安装 openssl 1.1d 版

/usr/local/Cellar/[email protected]/1.1.1d/lib/

add both libcrypto.a and libssl.a

添加 libcrypto.a 和 libssl.a

brew will not make a symbolic link to /usr/local/lib

brew 不会建立到 /usr/local/lib 的符号链接