我正在尝试使用node- yp创建一个可执行文件,从node.js链接到现有开源项目的共享库。
我可以将现有的开源项目(zmap)编译为共享对象,没有任何问题。我的问题是,一旦我的,因为缺乏一个更好的词,包装或可执行文件试图链接我收到"未定义的引用"错误。
简洁错误。
/Release/obj.target/zmap.so: undefined reference to `yylval'
./Release/obj.target/zmap.so: undefined reference to `yyparse'
collect2: ld returned 1 exit status
希望这是我错过的一些明显的东西。下面是导致错误的链接命令。
flock ./Release/linker.lock g++ -pthread -rdynamic -m64 -Wl,-rpath=$ORIGIN/lib.target/ -Wl,-rpath-link=./Release/lib.target/ -o Release/libzmap -Wl,--start-group ./Release/obj.target/libzmap/src/libzmap.o ./Release/obj.target/zmap.so -Wl,--end-group -pthread -lpcap -lgmp -lfl -lm
对象转储,nm &LDD所有存在于共享对象中的报告链接和功能。
%> nm build/Release/zmap.so | grep yylval
U yylval
%> nm build/Release/zmap.so | grep yyparse
U yyparse
%> ldd build/Release/zmap.so
linux-vdso.so.1 => (0x00007fffcfbff000)
libpcap.so.1 => /usr/lib64/libpcap.so.1 (0x00007f43a395b000)
libgmp.so.3 => /usr/lib64/libgmp.so.3 (0x00007f43a3700000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f43a33f9000)
libm.so.6 => /lib64/libm.so.6 (0x00007f43a3175000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f43a2f5f000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f43a2d41000)
libc.so.6 => /lib64/libc.so.6 (0x00007f43a29ad000)
/lib64/ld-linux-x86-64.so.2 (0x00007f43a3dda000)
libzmap.c文件的内容非常简单,只调用一个头文件并打印版本,这就是为什么我被错误难住的原因。
#include "zmap-1.2.1/src/zopt.h"
int main()
{
cmdline_parser_print_version();
return 0;
}
这里也是绑定。用于从工作的开放源码项目(zmap)中创建共享对象的Gyp文件,以及用于编译和链接包装器的部分。
{
"targets": [{
"target_name": "zmap",
"type": "shared_library",
"variables": {
'path': 'src/zmap-1.2.1',
'lexer': '<!(flex -o"<(path)/src/lexer.c" --header-file="<(path)/src/lexer.h" "<(path)/src/lexer.l")',
'parser': '<!(byacc -d -o "<(path)/src/parser.c" "<(path)/src/parser.y")',
},
"include_dirs": [
"<(path)/lib",
"<(path)/src",
"<(path)/src/output_modules",
],
"conditions": [
['OS=="linux"', {
"cflags": [
"-Wall",
"-Wformat=2",
"-Wno-format-nonliteral",
"-pedantic",
"-fno-strict-aliasing",
"-Wextra",
"-Wfloat-equal",
"-Wundef",
"-Wwrite-strings",
"-Wredundant-decls",
"-Wnested-externs",
"-Wbad-function-cast",
"-Winit-self",
"-Wmissing-noreturn",
"-Wstack-protector",
"-std=gnu99",
"-U_FORTIFY_SOURCE",
"-D_FORTIFY_SOURCE=2",
"-fstack-protector-all",
"-fwrapv",
"-fPIC",
"--param ssp-buffer-size=1",
"-O2",
],
"link_settings": {
"libraries": [
"-pthread",
"-lpcap",
"-lgmp",
"-lfl",
"-lm"
]
},
}]
],
"sources": [
"<(path)/lib/blacklist.c",
"<(path)/lib/constraint.c",
"<(path)/lib/logger.c",
"<(path)/lib/pbm.c",
"<(path)/lib/random.c",
"<(path)/lib/rijndael-alg-fst.c",
"<(path)/lib/xalloc.c",
"<(path)/src/aesrand.c",
"<(path)/src/cyclic.c",
"<(path)/src/expression.c",
"<(path)/src/fieldset.c",
"<(path)/src/filter.c",
"<(path)/src/get_gateway.c",
"<(path)/src/iterator.c",
"<(path)/src/lexer.c",
"<(path)/src/monitor.c",
"<(path)/src/send.c",
"<(path)/src/shard.c",
"<(path)/src/state.c",
"<(path)/src/recv.c",
"<(path)/src/validate.c",
"<(path)/src/zopt.c",
"<(path)/src/zmap.c",
"<(path)/src/output_modules/module_csv.c",
"<(path)/src/output_modules/output_modules.c",
"<(path)/src/probe_modules/module_icmp_echo.c",
"<(path)/src/probe_modules/module_tcp_synscan.c",
"<(path)/src/probe_modules/module_udp.c",
"<(path)/src/probe_modules/packet.c",
"<(path)/src/probe_modules/probe_modules.c"
]
},
{
"target_name": "libzmap",
"type": "executable",
"dependencies": [
"zmap",
],
"include_dirs": [
"<!(node -e "require('nan')")",
],
"sources": [
"src/libzmap.c",
],
"conditions": [
['OS=="linux"', {
"cflags": [
"-Wall",
"-Wformat=2",
"-Wno-format-nonliteral",
"-pedantic",
"-fno-strict-aliasing",
"-Wextra",
"-Wfloat-equal",
"-Wundef",
"-Wwrite-strings",
"-Wredundant-decls",
"-Wnested-externs",
"-Wbad-function-cast",
"-Winit-self",
"-Wmissing-noreturn",
"-Wstack-protector",
"-std=gnu99",
"-U_FORTIFY_SOURCE",
"-D_FORTIFY_SOURCE=2",
"-fstack-protector-all",
"-fwrapv",
"-fPIC",
"--param ssp-buffer-size=1",
"-O2",
],
"link_settings": {
"libraries": [
"-pthread",
"-lpcap",
"-lgmp",
"-lfl",
"-lm"
]
},
}]
],
}],
}
任何帮助都是感激的!
设置LD_LIBRARY_PATH,它将拾取共享对象,例如
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH;$(pwd)/build/Release