这个问题主要与node-gyp,GCC和NDK工具链有关,但是我将添加完整的上下文,因为可能有必要。
上下文
我正在使用React Native构建一个应用程序。由于我需要在此应用程序中使用节点本机库,因此我正在使用此节点模块nodejs-mobile在Android和iOS上运行Node.js进程。
添加composer-admin模块时,我遇到了Android编译问题。
错误
链接grpc_node
依赖项所需的composer-admin
模块时,编译器失败。错误是:
[LIB 1 PATH OMITTED] requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
...
[LIB N PATH OMITTED] requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
clang70++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [grpc_node.target.mk:189: Release/obj.target/grpc_node.node] Error 1
make: Leaving directory '/home/vanclief/Cacao_repos/react-app/android/build/nodejs-native-assets-temp-build/nodejs-native-assets-armeabi-v7a/nodejs-project/node_modules/fabric-client/node_modules/grpc/build'
奇怪的是,common.gypi中使用了-fPIC
标志:
/home/vanclief/Cacao_repos/react-app/android/build/standalone-toolchains/arm-linux-androideabi/bin/arm-linux-androideabi-clang++ -shared -g -rdynamic -fPIC -Wl,-soname=grpc_node.node -o
答案 0 :(得分:3)
common.gypi错误。它在ldflags中有-fPIC
。它必须在cflags中。
答案 1 :(得分:0)
您如何编辑common.gypi?
我遇到了一个非常相似的问题,错误非常相似requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
我看到common.gypi具有-fPIC的ldflags。我改为关注,但仍然遇到相同的问题。 请提供您的修复程序
['OS=="android"', {
'conditions': [
[ 'node_shared=="true"', {
'ldflags': [ '-fPIC' ],
'cflags':['-fPIC'],#Change 1
}]
],
'target_conditions': [
['_toolset=="target"', {
'defines': [ '_GLIBCXX_USE_C99_MATH' ],
'libraries': [ '-llog' ],
}],
[ '_type=="loadable_module"', {
'ldflags': [ '-fPIC' ],
'cflags':['-fPIC'],#Change 2
'conditions': [
# While loading a native node module, Android needs to have a
# (NEEDED) entry for libnode.so, or it won't be able to locate
# referenced symbols.
# We link to the binary libraries that are distributed with the
# nodejs-mobile headers so the (NEEDED) entry is created
[ 'target_arch=="arm"', {
'libraries': ['>(node_root_dir)/bin/armeabi-v7a/libnode.so'],
}],
[ 'target_arch=="arm64"', {
'libraries': ['>(node_root_dir)/bin/arm64-v8a/libnode.so'],
}],
[ 'target_arch=="x86"', {
'libraries': ['>(node_root_dir)/bin/x86/libnode.so'],
}],
[ 'target_arch=="x86_64"', {
'libraries': ['>(node_root_dir)/bin/x86_64/libnode.so'],
}],
],
}],
],
}],