Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?Embedding DLLs in a compiled executableLinking a shared library against a static library: must the static library be compiled differently than if an application were linking it?What is an application binary interface (ABI)?combine two GCC compiled .o object files into a third .o fileAndroid NDK: Link using a pre-compiled static libraryDifference between shared objects (.so), static libraries (.a), and DLL's (.so)?Compiling library in linux when in another folderFPC Compile as Static LibraryDoes the C++ standard allow for an uninitialized bool to crash a program?Are statically compiled pure standard C++ programs portable provided running on the same architecture?

Won 50K! Now what should I do with it

Why can't air tickets just accept only the passport number without any names?

Deep Learning based time series forecasting

Should you avoid redundant information after dialogue?

Was adding milk to tea started to reduce employee tea break time?

How to fit a linear model in the Bayesian way in Mathematica?

Alternatives to using writing paper for writing practice

Is it rude to tell recruiters I would only change jobs for a better salary?

Can a continent naturally split into two distant parts within a week?

How are "soeben" and "eben" different from one another?

Possible isometry groups of open manifolds

Can I capture stereo IQ signals from WebSDR?

Is killing off one of my queer characters homophobic?

Filtering fine silt/mud from water (not necessarily bacteria etc.)

How did John Lennon tune his guitar

Why does the trade federation become so alarmed upon learning the ambassadors are Jedi Knights?

Ragged justification of captions depending on odd/even page

How can I legally visit the United States Minor Outlying Islands in the Pacific?

Concatenation using + and += operator in Python

What impact would a dragon the size of Asia have on the environment?

Are L-functions uniquely determined by their values at negative integers?

Does optical correction give a more aesthetic look to the SBI logo?

(algebraic topology) question about the cellular approximation theorem

Confused about 誘われて (Sasowarete)



Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?


Embedding DLLs in a compiled executableLinking a shared library against a static library: must the static library be compiled differently than if an application were linking it?What is an application binary interface (ABI)?combine two GCC compiled .o object files into a third .o fileAndroid NDK: Link using a pre-compiled static libraryDifference between shared objects (.so), static libraries (.a), and DLL's (.so)?Compiling library in linux when in another folderFPC Compile as Static LibraryDoes the C++ standard allow for an uninitialized bool to crash a program?Are statically compiled pure standard C++ programs portable provided running on the same architecture?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I know that for full programs this is impossible because of executable file formats and syscalls, however if you had a file with:





int add(int a, int b)
return a + b;




Could you compile it as an object file or static library on Linux, and then use it on macOS or Windows?










share|improve this question



















  • 1





    Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

    – Mat
    Mar 25 at 19:28

















0















I know that for full programs this is impossible because of executable file formats and syscalls, however if you had a file with:





int add(int a, int b)
return a + b;




Could you compile it as an object file or static library on Linux, and then use it on macOS or Windows?










share|improve this question



















  • 1





    Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

    – Mat
    Mar 25 at 19:28













0












0








0








I know that for full programs this is impossible because of executable file formats and syscalls, however if you had a file with:





int add(int a, int b)
return a + b;




Could you compile it as an object file or static library on Linux, and then use it on macOS or Windows?










share|improve this question
















I know that for full programs this is impossible because of executable file formats and syscalls, however if you had a file with:





int add(int a, int b)
return a + b;




Could you compile it as an object file or static library on Linux, and then use it on macOS or Windows?







compilation linker operating-system abi object-files






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 7:19









Alexey Frunze

53.6k9 gold badges57 silver badges133 bronze badges




53.6k9 gold badges57 silver badges133 bronze badges










asked Mar 25 at 19:25









Alison DadAlison Dad

154 bronze badges




154 bronze badges







  • 1





    Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

    – Mat
    Mar 25 at 19:28












  • 1





    Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

    – Mat
    Mar 25 at 19:28







1




1





Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

– Mat
Mar 25 at 19:28





Object files and static libraries have file formats too, as much as executables. Then you have ABI issues.

– Mat
Mar 25 at 19:28












2 Answers
2






active

oldest

votes


















0















Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?




In theory; yes. Note that a compiler is just something that converts a primary language (e.g. C) into a secondary language (e.g. maybe native code for a specific OS and specific CPU; but maybe also BASIC source code or web-assembly source code or some kind of portable byte-code or anything else).



The only thing that really matters is that whatever uses the secondary language understands the secondary language.



In practice; for static libraries the secondary language includes things like object file formats and calling conventions; and "whatever uses the secondary language understands the secondary language" includes understanding the object file format, understanding the calling conventions, etc. Typically compilers are configured such that their secondary language matches whatever makes sense for the computer the compiler is running on, and because of this often you can't compile a static library on one computer and move it to another computer (with a different compiler and/or OS and/or CPU).



However, "typical" does not indicate a necessity. Cross-compilers are entirely possible.



For an example, you can port GCC (and it's tools - linker, etc) to Windows and use your cross-compiler to create static libraries that can be used by compiler's designed for (and running on) Linux; and if you do this you probably won't be able to use the cross compiler (running on Windows) to create static libraries for other compilers that are also running on Windows.






share|improve this answer






























    1














    Compiling a C code turns it into a native binary/ native image. It is specific to the processor/OS on which it is compiled (unless of course you are not using a cross compiler). The binary/object will not run on another OS.



    Only in case of languages like java, C# it is possible that you can compile for one OS and run on other (without rebuilding). This is because these languages create a managed binary/object. This managed object doesn't run directly on the OS. It runs on the virtual machine (JVM for Java and CLR for C#).






    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%2f55345096%2fcan-static-libraries-that-dont-rely-upon-the-c-standard-library-be-compiled-on%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









      0















      Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?




      In theory; yes. Note that a compiler is just something that converts a primary language (e.g. C) into a secondary language (e.g. maybe native code for a specific OS and specific CPU; but maybe also BASIC source code or web-assembly source code or some kind of portable byte-code or anything else).



      The only thing that really matters is that whatever uses the secondary language understands the secondary language.



      In practice; for static libraries the secondary language includes things like object file formats and calling conventions; and "whatever uses the secondary language understands the secondary language" includes understanding the object file format, understanding the calling conventions, etc. Typically compilers are configured such that their secondary language matches whatever makes sense for the computer the compiler is running on, and because of this often you can't compile a static library on one computer and move it to another computer (with a different compiler and/or OS and/or CPU).



      However, "typical" does not indicate a necessity. Cross-compilers are entirely possible.



      For an example, you can port GCC (and it's tools - linker, etc) to Windows and use your cross-compiler to create static libraries that can be used by compiler's designed for (and running on) Linux; and if you do this you probably won't be able to use the cross compiler (running on Windows) to create static libraries for other compilers that are also running on Windows.






      share|improve this answer



























        0















        Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?




        In theory; yes. Note that a compiler is just something that converts a primary language (e.g. C) into a secondary language (e.g. maybe native code for a specific OS and specific CPU; but maybe also BASIC source code or web-assembly source code or some kind of portable byte-code or anything else).



        The only thing that really matters is that whatever uses the secondary language understands the secondary language.



        In practice; for static libraries the secondary language includes things like object file formats and calling conventions; and "whatever uses the secondary language understands the secondary language" includes understanding the object file format, understanding the calling conventions, etc. Typically compilers are configured such that their secondary language matches whatever makes sense for the computer the compiler is running on, and because of this often you can't compile a static library on one computer and move it to another computer (with a different compiler and/or OS and/or CPU).



        However, "typical" does not indicate a necessity. Cross-compilers are entirely possible.



        For an example, you can port GCC (and it's tools - linker, etc) to Windows and use your cross-compiler to create static libraries that can be used by compiler's designed for (and running on) Linux; and if you do this you probably won't be able to use the cross compiler (running on Windows) to create static libraries for other compilers that are also running on Windows.






        share|improve this answer

























          0












          0








          0








          Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?




          In theory; yes. Note that a compiler is just something that converts a primary language (e.g. C) into a secondary language (e.g. maybe native code for a specific OS and specific CPU; but maybe also BASIC source code or web-assembly source code or some kind of portable byte-code or anything else).



          The only thing that really matters is that whatever uses the secondary language understands the secondary language.



          In practice; for static libraries the secondary language includes things like object file formats and calling conventions; and "whatever uses the secondary language understands the secondary language" includes understanding the object file format, understanding the calling conventions, etc. Typically compilers are configured such that their secondary language matches whatever makes sense for the computer the compiler is running on, and because of this often you can't compile a static library on one computer and move it to another computer (with a different compiler and/or OS and/or CPU).



          However, "typical" does not indicate a necessity. Cross-compilers are entirely possible.



          For an example, you can port GCC (and it's tools - linker, etc) to Windows and use your cross-compiler to create static libraries that can be used by compiler's designed for (and running on) Linux; and if you do this you probably won't be able to use the cross compiler (running on Windows) to create static libraries for other compilers that are also running on Windows.






          share|improve this answer














          Can static libraries that don't rely upon the C standard library be compiled on one OS, then moved to another?




          In theory; yes. Note that a compiler is just something that converts a primary language (e.g. C) into a secondary language (e.g. maybe native code for a specific OS and specific CPU; but maybe also BASIC source code or web-assembly source code or some kind of portable byte-code or anything else).



          The only thing that really matters is that whatever uses the secondary language understands the secondary language.



          In practice; for static libraries the secondary language includes things like object file formats and calling conventions; and "whatever uses the secondary language understands the secondary language" includes understanding the object file format, understanding the calling conventions, etc. Typically compilers are configured such that their secondary language matches whatever makes sense for the computer the compiler is running on, and because of this often you can't compile a static library on one computer and move it to another computer (with a different compiler and/or OS and/or CPU).



          However, "typical" does not indicate a necessity. Cross-compilers are entirely possible.



          For an example, you can port GCC (and it's tools - linker, etc) to Windows and use your cross-compiler to create static libraries that can be used by compiler's designed for (and running on) Linux; and if you do this you probably won't be able to use the cross compiler (running on Windows) to create static libraries for other compilers that are also running on Windows.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 6:40









          BrendanBrendan

          15.3k15 silver badges34 bronze badges




          15.3k15 silver badges34 bronze badges























              1














              Compiling a C code turns it into a native binary/ native image. It is specific to the processor/OS on which it is compiled (unless of course you are not using a cross compiler). The binary/object will not run on another OS.



              Only in case of languages like java, C# it is possible that you can compile for one OS and run on other (without rebuilding). This is because these languages create a managed binary/object. This managed object doesn't run directly on the OS. It runs on the virtual machine (JVM for Java and CLR for C#).






              share|improve this answer



























                1














                Compiling a C code turns it into a native binary/ native image. It is specific to the processor/OS on which it is compiled (unless of course you are not using a cross compiler). The binary/object will not run on another OS.



                Only in case of languages like java, C# it is possible that you can compile for one OS and run on other (without rebuilding). This is because these languages create a managed binary/object. This managed object doesn't run directly on the OS. It runs on the virtual machine (JVM for Java and CLR for C#).






                share|improve this answer

























                  1












                  1








                  1







                  Compiling a C code turns it into a native binary/ native image. It is specific to the processor/OS on which it is compiled (unless of course you are not using a cross compiler). The binary/object will not run on another OS.



                  Only in case of languages like java, C# it is possible that you can compile for one OS and run on other (without rebuilding). This is because these languages create a managed binary/object. This managed object doesn't run directly on the OS. It runs on the virtual machine (JVM for Java and CLR for C#).






                  share|improve this answer













                  Compiling a C code turns it into a native binary/ native image. It is specific to the processor/OS on which it is compiled (unless of course you are not using a cross compiler). The binary/object will not run on another OS.



                  Only in case of languages like java, C# it is possible that you can compile for one OS and run on other (without rebuilding). This is because these languages create a managed binary/object. This managed object doesn't run directly on the OS. It runs on the virtual machine (JVM for Java and CLR for C#).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 26 at 5:38









                  Syed.WarisSyed.Waris

                  6461 gold badge2 silver badges11 bronze badges




                  6461 gold badge2 silver badges11 bronze badges



























                      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%2f55345096%2fcan-static-libraries-that-dont-rely-upon-the-c-standard-library-be-compiled-on%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript