gpt4 book ai didi

c - node-gyp未定义引用问题

转载 作者:行者123 更新时间:2023-11-30 17:29:57 25 4
gpt4 key购买 nike

我正在尝试使用node-gyp创建一个可执行文件以从node.js使用,该可执行文件链接到现有开源项目的共享库。

我可以将现有的开源项目(zmap)编译为共享对象,没有任何问题。我的问题是,一旦我的,由于缺乏更好的词,包装器或可执行文件尝试链接,我就会收到“ undefined reference ”错误。

为简洁起见,错误。

/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) 创建共享对象的 binding.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,它将获取共享对象 ex。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH;$(pwd)/build/Release

关于c - node-gyp未定义引用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25434646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com