编译本机 C++ Node.js 模块,链接到 openSSL/libcrypto 失败

发布于 2024-11-16 08:27:20 字数 2001 浏览 4 评论 0原文

我正在使用 Cygwin/Windows,并且正在尝试为 node.js 构建本机模块。我打算使用 OpenSSL 库。我已经从 Cygwin 包管理器安装了 openssl。

我的 .cc 文件中有以下几行:

#include <openssl/dh.h>

但是

 DH*    public_dh_key = DH_new();

当我尝试使用 node-waf configure build 链接/编译它时,我得到:

undefined reference to _DH_new

编辑:

的一部分构建脚本:(

def build(bld):
  ppp= bld.new_task_gen('cxx', 'shlib', 'node_addon')
  ppp.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-L/usr/lib", "-lssl"]
...

我尝试添加 -lcrypto 但仍然得到相同的结果。我还尝试了“-lssl32”、“-lssleay32”、“-llibeay32”的各种组合。)

编辑

输出这构建脚本:

$ node-waf configure build
Checking for program g++ or c++          : /usr/bin/g++
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok
Checking for node path                   : not found
Checking for node prefix                 : ok /usr/local
'configure' finished successfully (0.330s)
Waf: Entering directory `/usr/src/build'
[1/2] cxx: ppp.cc -> build/default/ppp_1.o
[2/2] cxx_link: build/default/ppp_1.o -> build/default/ppp.node build/default/libppp.dll.a
Creating library file: default/libppp.dll.a
default/ppp_1.o:/usr/src/build/../ppp.cc:289: undefined reference to `_HMAC'
collect2: ld returned 1 exit status
Waf: Leaving directory `/usr/src/build'
Build failed:  -> task failed (err #1):
        {task: cxx_link ppp_1.o -> ppp.node,libppp.dll.a}

编辑

我在 usr/include/openssl 中有头文件 dh.h

并且在 /usr/lib/ 中有所需的文件(libssl32.dll、libeay32.dll 和 ssleay32.dll)

答案

jHackTheRipper 回答了这个问题并因此获得了荣誉,但最终的答案隐藏在他答案下面的评论中。总而言之,waf 的口头禅是

obj.lib='crypto'

I'm using Cygwin/Windows and I'm trying to build a native module for node.js. I intend to make use of the OpenSSL Library. I have installed openssl from the Cygwin package manager.

I have the following lines in my .cc file:

#include <openssl/dh.h>

and

 DH*    public_dh_key = DH_new();

But when I try to link/compile it with node-waf configure build, I get:

undefined reference to _DH_new

Edit:

Part of the build script:

def build(bld):
  ppp= bld.new_task_gen('cxx', 'shlib', 'node_addon')
  ppp.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall", "-L/usr/lib", "-lssl"]
...

(I have tried adding -lcrypto but still get the same result. I have also tried various combinations of "-lssl32","-lssleay32","-llibeay32".)

Edit

Output of the build script:

$ node-waf configure build
Checking for program g++ or c++          : /usr/bin/g++
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok
Checking for node path                   : not found
Checking for node prefix                 : ok /usr/local
'configure' finished successfully (0.330s)
Waf: Entering directory `/usr/src/build'
[1/2] cxx: ppp.cc -> build/default/ppp_1.o
[2/2] cxx_link: build/default/ppp_1.o -> build/default/ppp.node build/default/libppp.dll.a
Creating library file: default/libppp.dll.a
default/ppp_1.o:/usr/src/build/../ppp.cc:289: undefined reference to `_HMAC'
collect2: ld returned 1 exit status
Waf: Leaving directory `/usr/src/build'
Build failed:  -> task failed (err #1):
        {task: cxx_link ppp_1.o -> ppp.node,libppp.dll.a}

Edit

I have the header file dh.h in usr/include/openssl

And I have the required files (libssl32.dll, libeay32.dll and ssleay32.dll) in /usr/lib/

The answer

jHackTheRipper answered this and got the credit for it, but the final answer is buried in the comments beneath his answer. So to summarise, the waf mantra is

obj.lib='crypto'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-11-23 08:27:20

添加 -lcrypto 应该可以解决问题。
根据我系统上的 nm 输出 _DH_new_HMAC 似乎位于 libcrypto (OpenSSL 的一部分)动态库:

jhacktheripper@macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep _DH_new
0000000000036360 T _DH_new
0000000000036120 T _DH_new_method


jhacktheripper@macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep HMAC
0000000000090d40 T _HMAC
0000000000090c80 T _HMAC_CTX_cleanup
0000000000090910 T _HMAC_CTX_init
00000000000908c0 T _HMAC_CTX_set_flags
0000000000090940 T _HMAC_Final
0000000000090cc0 T _HMAC_Init
0000000000090a10 T _HMAC_Init_ex
0000000000090a00 T _HMAC_Update

Adding -lcrypto should do the trick.
According to the nm output on my system _DH_new and _HMAC seem to be in the libcrypto (part of OpenSSL) dynamic library :

jhacktheripper@macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep _DH_new
0000000000036360 T _DH_new
0000000000036120 T _DH_new_method


jhacktheripper@macbook-prolocal:~$ nm /usr/lib/libcrypto.dylib | grep HMAC
0000000000090d40 T _HMAC
0000000000090c80 T _HMAC_CTX_cleanup
0000000000090910 T _HMAC_CTX_init
00000000000908c0 T _HMAC_CTX_set_flags
0000000000090940 T _HMAC_Final
0000000000090cc0 T _HMAC_Init
0000000000090a10 T _HMAC_Init_ex
0000000000090a00 T _HMAC_Update
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文