gpt4 book ai didi

swift - 将 modulemap 用于 Swift 框架时 OpenSSL 库的非模块化 header

转载 作者:搜寻专家 更新时间:2023-10-31 19:40:10 25 4
gpt4 key购买 nike

我正在尝试使用 XCode 将 OpenSSL 库静态链接到我的 Swift 框架。网上提到的大多数方法都不正确,因为它们建议使用导入路径(SWIFT_INCLUDE_PATHS)。因此,框架二进制文件被锁定到文件系统中的特定位置,二进制文件本身不可移植。虽然这不是世界末日,但我仍然希望能够通过 Carthage 分发二进制文件,而遵循上述方法并不能实现这一点。

我尝试使用框架的伞头文件创建自己的模块映射,并将 OpenSSL 库作为显式模块包括在内,遵循以下文章中描述的方法:https://badootech.badoo.com/bundling-c-library-in-swift-framework-3d9dae950774

这是我的模块映射文件,我将其路径插入到 MODULEMAP_FILE 中构建配置变量。

framework module MyFramework {
umbrella header "MyFramework.h"
requires objc

export *
module * { export * }

module COpenSSL [system] {
header "shim.h"
link "ssl"
link "crypto"
export *
}
}

哪里shim.h文件是一个头文件,看起来像这样:

#ifndef __COPENSSL_SHIM_H__
#define __COPENSSL_SHIM_H__

#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/md4.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/rand.h>
#include <openssl/ripemd.h>
#include <openssl/pkcs12.h>
#include <openssl/x509v3.h>

__attribute__((swift_name("SSL_set_tlsext_host_name(_:_:)")))
static inline int shim_SSL_set_tlsext_host_name(const SSL *s, const char *name) {
return SSL_set_tlsext_host_name(s, name);
};

#endif

这里的问题是,我在尝试编译有关包含非模块化 header 的项目时遇到错误。

我试图将所有头文件作为公共(public)头文件( conf.hevp.h 等)包含到 XCode 项目中。但问题仍然存在,大概是因为它无法使用 header 包含的语法 #include <openssl/conf.h> .将夹杂物更改为 #include "conf.h"等工作,但随后将相同样式的 header 包含用于 conf.h以及来自 Open SSL 库的所有其他头文件,所以这并没有真正帮助。

我真的不想为了让它工作而修改 OpenSSL 库中的每个头文件,看来必须有一些更简单的方法来解决这个问题。

有没有办法不必将这些 header 包含到 XCode 项目中,以便它们仍然可以使用 #include <openssl/conf.h> 的原始语法? ?

我试过设置 HEADER_SEARCH_PATHS到每个 header 的相对路径为 openssl/conf.h 的路径等等,但它根本没有帮助。

谢谢。

最佳答案

最后,我找不到比将所有必需的 header 列到模块映射中并重写来自 <> 的 SSL 库文件的包含宏更好的解决方案了。只是普通包含的语法。我使用这个小 shell 脚本来帮助我:

sed -E -i '' 's/#[[:space:]]*include <openssl\/(.*).h>/#include \"\1\.h"/' $SCRIPT_DIR/../Libraries/openssl/include/openssl/*.h

关于swift - 将 modulemap 用于 Swift 框架时 OpenSSL 库的非模块化 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56599824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com