我正在尝试在我的项目中链接一个名为 librandomnumber.so 的预编译共享库文件。 CMakeLists.txt 的代码:
link_directories('lib/native_Library/librandomnumber.so')
add_library(native-lib librandomnumber.so)
target_link_libraries(native-lib librandomnumber.so)
加载库代码:
import 'dart:ffi';
import 'dart:io';
typedef fetch_number_func = Int32 Function();
typedef FetchNumber = int Function();
class FfiService {
get updateLocationsCommand => null;
Object fetchRandomNumber() {
if (Platform.isAndroid){
print("now going to load library");
final DynamicLibrary nativeAddLib = Platform.isAndroid
? DynamicLibrary.open('native-lib.so')
: DynamicLibrary.process();
print("sdgahhgjhdgajh" + nativeAddLib.toString());
final fetchNumberPointer =
nativeAddLib.lookup<NativeFunction<fetch_number_func>>(
'fetch_number',
);
return fetchNumberPointer;
}
else {
(exc){
DynamicLibrary.process();
print('Something went wrong in fetchRandomNumber ${exc.toString()}');
};
}
return 0;
}
}
显示此错误
错误:无效参数:无法加载动态库“native-lib.so”:dlopen 失败:未找到库“native-lib.so”
你能给我解决方案吗?