c++ - 将本地 Openssl 链接到 Nodejs C++ 插件

标签 c++ node.js openssl

我正在为使用 OpenSSL 3 的 Nodejs 编写一个 C++ 插件,当我尝试使用命令 node-gyp build 编译代码时,我不断收到此错误:

/Users/myuser/Library/Caches/node-gyp/17.0.1/include/node/openssl/macros.h:155:4: 错误:“OPENSSL_API_COMPAT 表示不可能的 API 兼容性级别”

我可以看到这里使用的 OpenSSL 包含在 NodeJS 文件夹中,有什么方法可以链接我在 mac M1 上用自制软件安装的 OpenSSL 库吗?

我的 binding.gyp 文件如下所示:

{
  "targets": [
    {
      "target_name": "module",
      "include_dirs": [ "/opt/homebrew/opt/openssl@3/include" ],
      "sources": [ "./module.cpp" ],
      "libraries": [
            "/opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib",
            "/opt/homebrew/opt/openssl@3/lib/libcrypto.a",
            "/opt/homebrew/opt/openssl@3/lib/libcrypto.dylib"
        ]
    }
    ]
}

最佳答案

这是 Node.js 中的一个问题:https://github.com/nodejs/node/issues/40575

这是一个解决方法:https://github.com/mmomtchev/node-gdal-async/commit/85816cbeff104b5484aae840fe43661c16cb6032

将这两个定义添加到您的 gyp 中:

"OPENSSL_API_COMPAT=0x10100001L",
"OPENSSL_CONFIGURED_API=0x30000000L"

我是问题和解决方法的作者。

关于c++ - 将本地 Openssl 链接到 Nodejs C++ 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70541687/

相关文章:

Rabbitmq.conf 文件中的 SSL 配置未应用于我的 rabbitmq-server

c++ - 更改 QRegion 的几何形状

node.js - 变量 LdapJS 中来自 LDAP 查询的数据

python - Celery 拒绝反序列化我的自定义序列化内容并抛出 ContentDisallowed Exception

node.js - 在node.js中使用passport.js登录Twitter不起作用

node.js - 请求模块导致express.js设置 header

erlang - Rabbitmq 2.2 无法在 Snow Leopard 上运行(SSL 错误)

c++ - MFC - 获取特定窗口的设备上下文

c++ - 使子类可以调用彼此的共享成员变量

c++ - 不同自定义类型的 unordered_map