How do you use gcc's ar utility with ocaml's compiler?












2















I can create a static library with ocaml object files using



ar rc ./lib/libprog.a ./_build/*.cmo


And I can display the contents of the libprog.a using



ar t ./lib/libprog.a


but I can't find any documentation that explains how to use this static library with ocaml's compilers.



Could someone please post an example(or provide a link) which demonstrates how to use a libprog.a file with ocaml's compilers. Please no examples with ocaml build utilities because I want to see how its done at the command line using ocaml's compilers. Thanks.










share|improve this question



























    2















    I can create a static library with ocaml object files using



    ar rc ./lib/libprog.a ./_build/*.cmo


    And I can display the contents of the libprog.a using



    ar t ./lib/libprog.a


    but I can't find any documentation that explains how to use this static library with ocaml's compilers.



    Could someone please post an example(or provide a link) which demonstrates how to use a libprog.a file with ocaml's compilers. Please no examples with ocaml build utilities because I want to see how its done at the command line using ocaml's compilers. Thanks.










    share|improve this question

























      2












      2








      2








      I can create a static library with ocaml object files using



      ar rc ./lib/libprog.a ./_build/*.cmo


      And I can display the contents of the libprog.a using



      ar t ./lib/libprog.a


      but I can't find any documentation that explains how to use this static library with ocaml's compilers.



      Could someone please post an example(or provide a link) which demonstrates how to use a libprog.a file with ocaml's compilers. Please no examples with ocaml build utilities because I want to see how its done at the command line using ocaml's compilers. Thanks.










      share|improve this question














      I can create a static library with ocaml object files using



      ar rc ./lib/libprog.a ./_build/*.cmo


      And I can display the contents of the libprog.a using



      ar t ./lib/libprog.a


      but I can't find any documentation that explains how to use this static library with ocaml's compilers.



      Could someone please post an example(or provide a link) which demonstrates how to use a libprog.a file with ocaml's compilers. Please no examples with ocaml build utilities because I want to see how its done at the command line using ocaml's compilers. Thanks.







      ocaml






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 20:26









      G4143G4143

      475617




      475617
























          1 Answer
          1






          active

          oldest

          votes


















          3














          OCaml wants to use its own archive format.



          $ cat a.ml
          let x = 14
          $ cat b.ml
          let y = 17
          $ cat main.ml
          let () = Printf.printf "%dn" (A.x + B.y)

          $ ocamlc -c a.ml
          $ ocamlc -c b.ml
          $ ocamlc -a -o oclibab.cma a.cmo b.cmo


          Now there is an OCaml archive (.cma file) named oclibab.cma that contains the modules A and B:



          $ ocamlobjinfo oclibab.cma
          File oclibab.cma
          Force custom: no
          Extra C object files:
          Extra C options:
          Extra dynamically-loaded libraries:
          Unit name: A
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          b162d96cf09fcde9d245f96359c9178a A
          Required globals:
          Uses unsafe features: no
          Force link: no
          Unit name: B
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          bc583fd68fc2b0a4e44e3e640983c8dd B
          Required globals:
          Uses unsafe features: no
          Force link: no


          Note that this archive format contains digital signatures for the interfaces. This allows stronger checking at link time than is generally available through the stock toolchain of the OS (like ar).



          $ ocamlc -o main oclibab.cma main.ml
          $ ./main
          31





          share|improve this answer


























          • So all the *.a files that are included with Ocaml are C files? Example unix.a.

            – G4143
            Nov 25 '18 at 21:06








          • 1





            If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

            – Jeffrey Scofield
            Nov 25 '18 at 21:18











          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%2f53471600%2fhow-do-you-use-gccs-ar-utility-with-ocamls-compiler%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          OCaml wants to use its own archive format.



          $ cat a.ml
          let x = 14
          $ cat b.ml
          let y = 17
          $ cat main.ml
          let () = Printf.printf "%dn" (A.x + B.y)

          $ ocamlc -c a.ml
          $ ocamlc -c b.ml
          $ ocamlc -a -o oclibab.cma a.cmo b.cmo


          Now there is an OCaml archive (.cma file) named oclibab.cma that contains the modules A and B:



          $ ocamlobjinfo oclibab.cma
          File oclibab.cma
          Force custom: no
          Extra C object files:
          Extra C options:
          Extra dynamically-loaded libraries:
          Unit name: A
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          b162d96cf09fcde9d245f96359c9178a A
          Required globals:
          Uses unsafe features: no
          Force link: no
          Unit name: B
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          bc583fd68fc2b0a4e44e3e640983c8dd B
          Required globals:
          Uses unsafe features: no
          Force link: no


          Note that this archive format contains digital signatures for the interfaces. This allows stronger checking at link time than is generally available through the stock toolchain of the OS (like ar).



          $ ocamlc -o main oclibab.cma main.ml
          $ ./main
          31





          share|improve this answer


























          • So all the *.a files that are included with Ocaml are C files? Example unix.a.

            – G4143
            Nov 25 '18 at 21:06








          • 1





            If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

            – Jeffrey Scofield
            Nov 25 '18 at 21:18
















          3














          OCaml wants to use its own archive format.



          $ cat a.ml
          let x = 14
          $ cat b.ml
          let y = 17
          $ cat main.ml
          let () = Printf.printf "%dn" (A.x + B.y)

          $ ocamlc -c a.ml
          $ ocamlc -c b.ml
          $ ocamlc -a -o oclibab.cma a.cmo b.cmo


          Now there is an OCaml archive (.cma file) named oclibab.cma that contains the modules A and B:



          $ ocamlobjinfo oclibab.cma
          File oclibab.cma
          Force custom: no
          Extra C object files:
          Extra C options:
          Extra dynamically-loaded libraries:
          Unit name: A
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          b162d96cf09fcde9d245f96359c9178a A
          Required globals:
          Uses unsafe features: no
          Force link: no
          Unit name: B
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          bc583fd68fc2b0a4e44e3e640983c8dd B
          Required globals:
          Uses unsafe features: no
          Force link: no


          Note that this archive format contains digital signatures for the interfaces. This allows stronger checking at link time than is generally available through the stock toolchain of the OS (like ar).



          $ ocamlc -o main oclibab.cma main.ml
          $ ./main
          31





          share|improve this answer


























          • So all the *.a files that are included with Ocaml are C files? Example unix.a.

            – G4143
            Nov 25 '18 at 21:06








          • 1





            If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

            – Jeffrey Scofield
            Nov 25 '18 at 21:18














          3












          3








          3







          OCaml wants to use its own archive format.



          $ cat a.ml
          let x = 14
          $ cat b.ml
          let y = 17
          $ cat main.ml
          let () = Printf.printf "%dn" (A.x + B.y)

          $ ocamlc -c a.ml
          $ ocamlc -c b.ml
          $ ocamlc -a -o oclibab.cma a.cmo b.cmo


          Now there is an OCaml archive (.cma file) named oclibab.cma that contains the modules A and B:



          $ ocamlobjinfo oclibab.cma
          File oclibab.cma
          Force custom: no
          Extra C object files:
          Extra C options:
          Extra dynamically-loaded libraries:
          Unit name: A
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          b162d96cf09fcde9d245f96359c9178a A
          Required globals:
          Uses unsafe features: no
          Force link: no
          Unit name: B
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          bc583fd68fc2b0a4e44e3e640983c8dd B
          Required globals:
          Uses unsafe features: no
          Force link: no


          Note that this archive format contains digital signatures for the interfaces. This allows stronger checking at link time than is generally available through the stock toolchain of the OS (like ar).



          $ ocamlc -o main oclibab.cma main.ml
          $ ./main
          31





          share|improve this answer















          OCaml wants to use its own archive format.



          $ cat a.ml
          let x = 14
          $ cat b.ml
          let y = 17
          $ cat main.ml
          let () = Printf.printf "%dn" (A.x + B.y)

          $ ocamlc -c a.ml
          $ ocamlc -c b.ml
          $ ocamlc -a -o oclibab.cma a.cmo b.cmo


          Now there is an OCaml archive (.cma file) named oclibab.cma that contains the modules A and B:



          $ ocamlobjinfo oclibab.cma
          File oclibab.cma
          Force custom: no
          Extra C object files:
          Extra C options:
          Extra dynamically-loaded libraries:
          Unit name: A
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          b162d96cf09fcde9d245f96359c9178a A
          Required globals:
          Uses unsafe features: no
          Force link: no
          Unit name: B
          Interfaces imported:
          9b04ecdc97e5102c1d342892ef7ad9a2 Pervasives
          79ae8c0eb753af6b441fe05456c7970b CamlinternalFormatBasics
          bc583fd68fc2b0a4e44e3e640983c8dd B
          Required globals:
          Uses unsafe features: no
          Force link: no


          Note that this archive format contains digital signatures for the interfaces. This allows stronger checking at link time than is generally available through the stock toolchain of the OS (like ar).



          $ ocamlc -o main oclibab.cma main.ml
          $ ./main
          31






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 20:54

























          answered Nov 25 '18 at 20:48









          Jeffrey ScofieldJeffrey Scofield

          48.5k24979




          48.5k24979













          • So all the *.a files that are included with Ocaml are C files? Example unix.a.

            – G4143
            Nov 25 '18 at 21:06








          • 1





            If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

            – Jeffrey Scofield
            Nov 25 '18 at 21:18



















          • So all the *.a files that are included with Ocaml are C files? Example unix.a.

            – G4143
            Nov 25 '18 at 21:06








          • 1





            If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

            – Jeffrey Scofield
            Nov 25 '18 at 21:18

















          So all the *.a files that are included with Ocaml are C files? Example unix.a.

          – G4143
          Nov 25 '18 at 21:06







          So all the *.a files that are included with Ocaml are C files? Example unix.a.

          – G4143
          Nov 25 '18 at 21:06






          1




          1





          If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

          – Jeffrey Scofield
          Nov 25 '18 at 21:18





          If you make an archive of bytecode (.cmo) files, ocamlc makes a .cma file. If you make an archive of native (.cmx) files, ocamlopt makes a .cmxa file and a .a file. So not all .a files are from .c sources. Some of them are, most likely.

          – Jeffrey Scofield
          Nov 25 '18 at 21:18




















          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%2f53471600%2fhow-do-you-use-gccs-ar-utility-with-ocamls-compiler%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

          Wiesbaden

          To store a contact into the json file from server.js file using a class in NodeJS

          Marschland