I am attempting to use node-gyp to create an executable to use from node.js which links to shared library from an existing open source project.
I can compile the existing open source project (zmap) as a shared object without any problems. My problem is that once my, for lack of a better word, wrapper or executable attempts to link I am receiving 'undefined reference' errors.
The error for brevity.
/Release/obj.target/zmap.so: undefined reference to `yylval'
./Release/obj.target/zmap.so: undefined reference to `yyparse'
collect2: ld returned 1 exit status
Hopefully this is something obvious I am missing. Here is the linking command that is causing the errors.
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
Object dump, nm & ldd all report linking and functions existing within the shared object.
%> 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)
The contents of the libzmap.c file is super simple and only calls one header file and prints the version which is why I am stumped on the error.
#include "zmap-1.2.1/src/zopt.h"
int main()
{
cmdline_parser_print_version();
return 0;
}
Here is also the binding.gyp file being used to create the shared object from the working open source project (zmap) as well as the section used to compile and link the wrapper.
{
"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"
]
},
}]
],
}],
}
Any help is appreciated!
Set the LD_LIBRARY_PATH and it will pick up the shared object ex.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH;$(pwd)/build/Release