C 节点gyp未定义引用问题

C 节点gyp未定义引用问题,c,node.js,node-gyp,flock,C,Node.js,Node Gyp,Flock,我正试图使用node gyp创建一个可执行文件,以便使用from node.js从现有的开源项目链接到共享库 我可以将现有的开源项目(zmap)编译为一个共享对象,没有任何问题。我的问题是,一旦我的链接失败,由于缺少更好的单词、包装器或可执行文件,我就会收到“未定义引用”错误 为简洁起见,这是一个错误 /Release/obj.target/zmap.so: undefined reference to `yylval' ./Release/obj.target/zmap.so: undefin

我正试图使用node gyp创建一个可执行文件,以便使用from 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;
}
这里还有binding.gyp文件,用于从正在工作的开源项目(zmap)创建共享对象,以及用于编译和链接包装器的部分

{
  "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"
          ]
        },
      }]
    ],
  }],
}
{
“目标”:[{
“目标名称”:“zmap”,
“类型”:“共享_库”,
“变量”:{
“路径”:“src/zmap-1.2.1”,

“lexer”:“设置LD_LIBRARY_路径,它将拾取共享对象

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