【求助】使用ffi调用so库时发生invalid mode for dlopen(): Invalid argument这个错误,请大神指教
const ref = require('ref');
const ffi = require('ffi');
const FPmatch = ffi.DynamicLibrary('libzazlibarm32', {
'UserMatch': [ 'int', [ 'string', 'string', 'string', 'int *' ]],
});
let score= ref.alloc(ref.types.int, 666);
const int = FPmatch.UserMatch('abc','abc', '3', score);
console.log(int, score);
\n```
libzazlibarm32已放到了/usr/local/lib目录下
```js\n
#ifndef __LIB_OPTICMATCH_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
函数名称: int UserMatch(unsigned char *Src,unsigned char *Dst,unsigned char SecuLevel,int *MatchScore)
函数功能: 按照指定安全级别对两枚特征文件进行比对
函数参数: unsigned char *SrcFile 特征文件指针(256bytes)
unsigned char *DstFile 特征文件指针(256bytes)
unsigned char SecuLevel 安全等级(1/2/3/4/5)
int *MatchScore 返回比对得分
返回参数: 0:不匹配或安全等级指定错误
1:指定的两枚特征匹配
*/
int UserMatch(unsigned char *Src,unsigned char *Dst,unsigned char SecuLevel,int *MatchScore);
#ifdef __cplusplus
}
#endif
#define __LIB_OPTICMATCH_H__
#endif
\n```
错误提示
```js\n
/home/nodejs/adserver/node_modules/ffi/lib/dynamic_library.js:74
throw new Error('Dynamic Linking Error: ' + err)
^
Error: Dynamic Linking Error: libzazlib32: invalid mode for dlopen(): Invalid argument
at new DynamicLibrary (/home/nodejs/adserver/node_modules/ffi/lib/dynamic_library.js:74:11)
at Object.DynamicLibrary (/home/nodejs/adserver/node_modules/ffi/lib/dynamic_library.js:33:12)
at Object.<anonymous> (/home/nodejs/adserver/test.js:3:21)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:390:7)
\n```
4 回复
ffi有DynamicLibrary这个方法?
unsigned char *Src,unsigned char *Ds 前两个参数都是指针类型, ffi那儿定义应该从"string" 改为 “pointer”
FPmatch.UserMatch(‘abc’,‘abc’, ‘3’, score);
改为
FPmatch.UserMatch(Buffer.from(‘abc\0’) ,
Buffer.from( ‘abc\0’ ) , ‘3’ , score);
@waitingsong 感谢,后面这个问题解决了。原来是提供的so库不是arm cpu上编译的。