为Node.js编译本地C ++模块,链接到openSSL / libcrypto失败
我正在使用Cygwin / Windows,我正在尝试为node.js构build本地模块。 我打算使用OpenSSL库。 我已经从Cygwin软件包pipe理器安装了openssl。
我的.cc文件中有以下几行:
#include <openssl/dh.h>
和
DH* public_dh_key = DH_new();
但是当我尝试链接/编译它与node-waf configure build
,我得到:
undefined reference to _DH_new
编辑:
构build脚本的一部分:
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”。)
编辑
构build脚本的输出:
$ 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 / lib目录下有需要的文件(libssl32.dll,libeay32.dll和ssleay32.dll)
答案
jHackTheRipper回答了这个问题并得到了信任,但是最终的答案却被埋在了他的回答下面的评论中。 所以总结一下,waf的口头禅是
obj.lib='crypto'
添加-lcrypto
应该做的伎俩。
根据我的系统上的nm
输出_DH_new
和_HMAC
似乎在libcrypto
(OpenSSL的一部分)dynamic库中:
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