Unable to link libraries when compiling native node modules to Android. Recompile with -fPIC issue when using...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















This question is mostly related to node-gyp, GCC and the NDK toolchain, but I will add the full context because it may be necessary.



Context



I am building an App using React Native. Since I need to use node native libraries in this App, I am using this node module nodejs-mobile for running a Node.js process on Android and iOS.



When adding the composer-admin module, I am having compilation issues for Android.



Error



The compiler is failing when linking the grpc_node module which is required by a composer-admin dependency. The error is:




[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'



The weird thing is the -fPIC flag is being used as specified in the common.gypi:




/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



This is the full compilation log










share|improve this question





























    1















    This question is mostly related to node-gyp, GCC and the NDK toolchain, but I will add the full context because it may be necessary.



    Context



    I am building an App using React Native. Since I need to use node native libraries in this App, I am using this node module nodejs-mobile for running a Node.js process on Android and iOS.



    When adding the composer-admin module, I am having compilation issues for Android.



    Error



    The compiler is failing when linking the grpc_node module which is required by a composer-admin dependency. The error is:




    [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'



    The weird thing is the -fPIC flag is being used as specified in the common.gypi:




    /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



    This is the full compilation log










    share|improve this question

























      1












      1








      1








      This question is mostly related to node-gyp, GCC and the NDK toolchain, but I will add the full context because it may be necessary.



      Context



      I am building an App using React Native. Since I need to use node native libraries in this App, I am using this node module nodejs-mobile for running a Node.js process on Android and iOS.



      When adding the composer-admin module, I am having compilation issues for Android.



      Error



      The compiler is failing when linking the grpc_node module which is required by a composer-admin dependency. The error is:




      [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'



      The weird thing is the -fPIC flag is being used as specified in the common.gypi:




      /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



      This is the full compilation log










      share|improve this question














      This question is mostly related to node-gyp, GCC and the NDK toolchain, but I will add the full context because it may be necessary.



      Context



      I am building an App using React Native. Since I need to use node native libraries in this App, I am using this node module nodejs-mobile for running a Node.js process on Android and iOS.



      When adding the composer-admin module, I am having compilation issues for Android.



      Error



      The compiler is failing when linking the grpc_node module which is required by a composer-admin dependency. The error is:




      [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'



      The weird thing is the -fPIC flag is being used as specified in the common.gypi:




      /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



      This is the full compilation log







      gcc android-ndk node-gyp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 18 '18 at 15:57









      FrancoFranco

      347213




      347213
























          2 Answers
          2






          active

          oldest

          votes


















          3














          common.gypi is wrong. It has -fPIC in ldflags. It needs to be in cflags.






          share|improve this answer
























          • I wish I had asked before, thank you.

            – Franco
            Oct 19 '18 at 2:00



















          0














          How did you edit the common.gypi?
          I am having a very similar issue with very same error requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC



          I see that common.gypi has ldflags for -fPIC. I changed to following but still get the same issue.
          Please provide your fix



          ['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'],
          }],
          ],
          }],
          ],
          }],





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52878047%2funable-to-link-libraries-when-compiling-native-node-modules-to-android-recompil%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            common.gypi is wrong. It has -fPIC in ldflags. It needs to be in cflags.






            share|improve this answer
























            • I wish I had asked before, thank you.

              – Franco
              Oct 19 '18 at 2:00
















            3














            common.gypi is wrong. It has -fPIC in ldflags. It needs to be in cflags.






            share|improve this answer
























            • I wish I had asked before, thank you.

              – Franco
              Oct 19 '18 at 2:00














            3












            3








            3







            common.gypi is wrong. It has -fPIC in ldflags. It needs to be in cflags.






            share|improve this answer













            common.gypi is wrong. It has -fPIC in ldflags. It needs to be in cflags.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 18 '18 at 18:11









            Dan AlbertDan Albert

            5,61911753




            5,61911753













            • I wish I had asked before, thank you.

              – Franco
              Oct 19 '18 at 2:00



















            • I wish I had asked before, thank you.

              – Franco
              Oct 19 '18 at 2:00

















            I wish I had asked before, thank you.

            – Franco
            Oct 19 '18 at 2:00





            I wish I had asked before, thank you.

            – Franco
            Oct 19 '18 at 2:00













            0














            How did you edit the common.gypi?
            I am having a very similar issue with very same error requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC



            I see that common.gypi has ldflags for -fPIC. I changed to following but still get the same issue.
            Please provide your fix



            ['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'],
            }],
            ],
            }],
            ],
            }],





            share|improve this answer




























              0














              How did you edit the common.gypi?
              I am having a very similar issue with very same error requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC



              I see that common.gypi has ldflags for -fPIC. I changed to following but still get the same issue.
              Please provide your fix



              ['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'],
              }],
              ],
              }],
              ],
              }],





              share|improve this answer


























                0












                0








                0







                How did you edit the common.gypi?
                I am having a very similar issue with very same error requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC



                I see that common.gypi has ldflags for -fPIC. I changed to following but still get the same issue.
                Please provide your fix



                ['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'],
                }],
                ],
                }],
                ],
                }],





                share|improve this answer













                How did you edit the common.gypi?
                I am having a very similar issue with very same error requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC



                I see that common.gypi has ldflags for -fPIC. I changed to following but still get the same issue.
                Please provide your fix



                ['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'],
                }],
                ],
                }],
                ],
                }],






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 4 at 2:30









                jollyjolly

                690613




                690613






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52878047%2funable-to-link-libraries-when-compiling-native-node-modules-to-android-recompil%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'