5
我正在为AWS lambda开发本地节点模块。此节点模块需要json-c静态链接不适用于节点模块
根据AWS lambda guidelines节点模块不应具有动态依赖关系。所以尝试链接json-c库的静态版本。但是我得到编译时错误。
为节点模块仅仅是一个共享库,我写了一个sample C application(与主更名)来模拟节点模块编写,这些都是结果:
g++ -shared -pthread -rdynamic -m64 -Wl,-soname=addon.node -o addon.node testjson.cpp -I /usr/include/json-c/ -L /lib/x86_64-linux-gnu/ -l:libjson-c.a
testjson.cpp: In function ‘int test()’:
testjson.cpp:6:14: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
char *str = "{ \"msg-type\": [ \"0xdeadbeef\", \"irc log\" ], \
^
/usr/bin/ld: /tmp/ccihB9d8.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccihB9d8.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
当我试图用“ - 整个档案“:
g++ -shared -o libshared.so -Wl,--whole-archive -fPIC -l:/usr/lib/x86_64-linux-gnu/libjson-c.a -Wl,--no-whole-archive testjson.cpp -I /usr/include/json-c/
testjson.cpp: In function ‘int test()’:
testjson.cpp:6:14: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
char *str = "{ \"msg-type\": [ \"0xdeadbeef\", \"irc log\" ], \
^
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libjson-c.a(json_c_version.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-gnu/libjson-c.a(json_c_version.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
我在做什么错?是不是可以静态链接库到共享对象?
您是否尝试在vanilla Amazon Linux AMI上构建您的模块?这可能会提示Lambda正在运行的内容。 – kixorz