Sharing C functions between two XS Perl modues











up vote
2
down vote

favorite












I have a Perl module A that is a XS based module. I have an A.xs file, and an aux_A.c file, where I have some standard C functions. I use DynaLoader, and it works file.



Now, I have a new module B, that is also a XS module. I also have the B.xs file, and the aux_B.c file. Now, I want that a standard C function defined in aux_B.c file to be able to use a function defined in aux_A.c file.



One option is to make A module to create a standard C library, and link B module with it. But I was trying to get away from that option.



Is there any other way to go?



What I am currently getting is DynaLoader complaining on undefined symbol when trying to load the B.so library.



Thanks
Alberto










share|improve this question


























    up vote
    2
    down vote

    favorite












    I have a Perl module A that is a XS based module. I have an A.xs file, and an aux_A.c file, where I have some standard C functions. I use DynaLoader, and it works file.



    Now, I have a new module B, that is also a XS module. I also have the B.xs file, and the aux_B.c file. Now, I want that a standard C function defined in aux_B.c file to be able to use a function defined in aux_A.c file.



    One option is to make A module to create a standard C library, and link B module with it. But I was trying to get away from that option.



    Is there any other way to go?



    What I am currently getting is DynaLoader complaining on undefined symbol when trying to load the B.so library.



    Thanks
    Alberto










    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a Perl module A that is a XS based module. I have an A.xs file, and an aux_A.c file, where I have some standard C functions. I use DynaLoader, and it works file.



      Now, I have a new module B, that is also a XS module. I also have the B.xs file, and the aux_B.c file. Now, I want that a standard C function defined in aux_B.c file to be able to use a function defined in aux_A.c file.



      One option is to make A module to create a standard C library, and link B module with it. But I was trying to get away from that option.



      Is there any other way to go?



      What I am currently getting is DynaLoader complaining on undefined symbol when trying to load the B.so library.



      Thanks
      Alberto










      share|improve this question













      I have a Perl module A that is a XS based module. I have an A.xs file, and an aux_A.c file, where I have some standard C functions. I use DynaLoader, and it works file.



      Now, I have a new module B, that is also a XS module. I also have the B.xs file, and the aux_B.c file. Now, I want that a standard C function defined in aux_B.c file to be able to use a function defined in aux_A.c file.



      One option is to make A module to create a standard C library, and link B module with it. But I was trying to get away from that option.



      Is there any other way to go?



      What I am currently getting is DynaLoader complaining on undefined symbol when trying to load the B.so library.



      Thanks
      Alberto







      c perl libraries xs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 12:20









      Alberto

      193117




      193117
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          To make module A export its C symbols with DynaLoader, you have to add the following to A.pm:



          sub dl_load_flags { 1 }


          This is badly documented, unfortunately. See this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen which makes its symbols available to other shared objects.






          share|improve this answer























          • Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
            – Alberto
            Nov 10 at 14:40











          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',
          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%2f53238891%2fsharing-c-functions-between-two-xs-perl-modues%23new-answer', 'question_page');
          }
          );

          Post as a guest
































          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          To make module A export its C symbols with DynaLoader, you have to add the following to A.pm:



          sub dl_load_flags { 1 }


          This is badly documented, unfortunately. See this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen which makes its symbols available to other shared objects.






          share|improve this answer























          • Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
            – Alberto
            Nov 10 at 14:40















          up vote
          4
          down vote



          accepted










          To make module A export its C symbols with DynaLoader, you have to add the following to A.pm:



          sub dl_load_flags { 1 }


          This is badly documented, unfortunately. See this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen which makes its symbols available to other shared objects.






          share|improve this answer























          • Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
            – Alberto
            Nov 10 at 14:40













          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          To make module A export its C symbols with DynaLoader, you have to add the following to A.pm:



          sub dl_load_flags { 1 }


          This is badly documented, unfortunately. See this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen which makes its symbols available to other shared objects.






          share|improve this answer














          To make module A export its C symbols with DynaLoader, you have to add the following to A.pm:



          sub dl_load_flags { 1 }


          This is badly documented, unfortunately. See this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen which makes its symbols available to other shared objects.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 16:33

























          answered Nov 10 at 13:19









          nwellnhof

          22.8k45779




          22.8k45779












          • Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
            – Alberto
            Nov 10 at 14:40


















          • Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
            – Alberto
            Nov 10 at 14:40
















          Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
          – Alberto
          Nov 10 at 14:40




          Thanks. I noticed this entry in the DynaLoader doc, but it wasn't clear. Thank you!
          – Alberto
          Nov 10 at 14:40


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238891%2fsharing-c-functions-between-two-xs-perl-modues%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          Popular posts from this blog

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."