1

我正在使用 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'
4

1 回答 1

1

添加-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
于 2011-07-04T06:43:24.740 回答