XCode 在 /usr/include 中找不到 OpenSSL 标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2785021/
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-14 19:20:22  来源:igfitidea点击:

XCode can't find OpenSSL headers in /usr/include

xcodemacosopensslheader-filesinclude

提问by mindthief

I'm trying to use standard system header files in my C++ XCode project:

我正在尝试在我的 C++ XCode 项目中使用标准系统头文件:

#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

The build fails and it complains:

构建失败并抱怨:

"Openssl/bio.h: No such file or directory"

I added /usr/include to the "Header Search Paths" in Project settings, but that doesn't fix it.

我在项目设置的“标题搜索路径”中添加了 /usr/include ,但这并没有解决它。

I can fix it by adding the whole path like:

我可以通过添加整个路径来修复它,例如:

#include </usr/include/openssl/bio.h>

-- but the project is full of similar includes and I don't want to change all of them this way. Also, I feel I shouldn't have to do this.

-- 但该项目充满了类似的包含,我不想以这种方式更改所有内容。另外,我觉得我不应该这样做。

Another way to fix it would be as another thread mentioned, which is to add /usr/include to UserHeader Search Paths. But if I do that, then I'd have to change all the angle brackets <> to quotes "", which again seems like a hack. I mean, these are standard system header files so I feel it should be something simple, not requiring these kinds of hacks.

修复它的另一种方法是提到的另一个线程,即将 /usr/include 添加到用户标题搜索路径。但是,如果我这样做,那么我必须将所有尖括号 <> 更改为引号“”,这再次看起来像是一个黑客。我的意思是,这些是标准的系统头文件,所以我觉得它应该很简单,不需要这些类型的黑客。

Any ideas?

有任何想法吗?

Thanks!

谢谢!

回答by Paul R

Xcode uses the currently selected SDK as a base path, which it prefixes on to system includes. So if your SDK is /Developer/SDKs/MacOSX10.6.sdkthen it will look under /Developer/SDKs/MacOSX10.6.sdk/usr/includeby default for system includes.

Xcode 使用当前选择的 SDK 作为基本路径,它作为系统包含的前缀。因此,如果您的 SDK 是,/Developer/SDKs/MacOSX10.6.sdk那么/Developer/SDKs/MacOSX10.6.sdk/usr/include默认情况下它会查看系统包含的内容。

There are various possible workarounds - I would probably just put a symbolic link in /Developer/SDKs/MacOSX10.6.sdk/usr/includepointing at /usr/include/opensslbut you can probably think of others now that you know the underlying problem.

有各种可能的解决方法 - 我可能只是在/Developer/SDKs/MacOSX10.6.sdk/usr/include指向中放置一个符号链接,/usr/include/openssl但既然您知道潜在的问题,您可能会想到其他方法。

回答by polettix

It might depend on the fact that HFS(+) is case insensitive. The error message talks about "Openssl/bio.h" with capital "O", but you're specifying "openssl/bio.h" in the include and the path with /usr/include works.

这可能取决于 HFS(+) 不区分大小写的事实。错误消息谈论“Openssl/bio.h”,大写字母“O”,但您在包含中指定了“openssl/bio.h”,而 /usr/include 的路径有效。

I suspect that there's some "Openssl" (capital "O") directory in your include path, that gets used when looking for "openssl/bio.h". This wouldn't happen if HFS(+) were case sensitive from the very beginning (I know it's possible to have is case sensitive, but it's actually a PITA to use...)

我怀疑您的包含路径中有一些“Openssl”(大写“O”)目录,在查找“openssl/bio.h”时会用到这些目录。如果 HFS(+) 从一开始就区分大小写,则不会发生这种情况(我知道可能区分大小写,但它实际上是一个 PITA 使用...)

回答by leontx

I've been able to avoid having to specify paths on includes by simply making sure to select Create groups for any added foldersfor the Foldersoption in the Add Files to Project dialogwhich pops up when you're adding the files.

通过简单地确保在添加文件时弹出的“将文件添加到项目”对话框中的文件夹”选项中选择“为任何添加的文件夹创建组”,我已经能够避免在包含上指定路径。

With the other option, Create folder reference for any added folders, I have to manually point it to the file via the full path (and the folder icons show up blue instead of the normal beige). Interestingly, even in this case, AutoComplete sees the file, but Xcode complains it can't find it.

使用另一个选项,为任何添加的文件夹创建文件夹引用,我必须通过完整路径手动将其指向文件(文件夹图标显示为蓝色而不是正常的米色)。有趣的是,即使在这种情况下,AutoComplete 也能看到文件,但 Xcode 抱怨它找不到它。