Integrating libraries or exe's complied on different compilers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shyam.lingegowda@gmail.com

    Integrating libraries or exe's complied on different compilers

    Hi all,

    If I have two c++ programs and I compile that using two different
    compilers on Unix. Is it possible for these two exe's to communicate
    with one another. Since the way the exe's are generated by two
    different compilers are different is it possible to communicate at
    all. Is there any alternative for the same. What about libraries
    compiled with two different compilers. If someone can give some
    feedback on the same it will be of great help.

    Regards,
    Sh
  • Paavo Helde

    #2
    Re: Integrating libraries or exe's complied on different compilers

    shyam.lingegowd a@gmail.com kirjutas:
    Hi all,
    >
    If I have two c++ programs and I compile that using two different
    compilers on Unix. Is it possible for these two exe's to communicate
    with one another. Since the way the exe's are generated by two
    different compilers are different is it possible to communicate at
    I hope you are aware that your browser is able to communicate with a web
    server regardless of by which compiler the webserver is compiled. This is
    in general true for any two applications: agree on a communication
    channel and use an external format which does not depend on compiler-
    specific details like type sizes or struct padding.
    all. Is there any alternative for the same. What about libraries
    compiled with two different compilers. If someone can give some
    You probably mean whether you can link together C++ libraries compiled by
    different compilers. This is undefined by the standard, meaning that you
    cannot do this portably.

    It is only possible if both compilers follow the same ABI (application
    binary interface). The ABI is typically defined for a certain combination
    of a language platform, e.g. C++ ABI for Linux on x86_64. I believe there
    are some platforms with standardized C++ ABI, so if both compilers follow
    this, they should be able to talk to each other.

    However, this is not enough. For example, if one library uses small-
    string optimization for std::string and the other does not, then any
    attempt to pass a std::string from one library to another will most
    probably fail miserably. This is where the one-definition-rule of C++
    kicks in, I guess - if the libraries are using different std::string
    definitions, the result is undefined. So all this business is very
    implementation-defined and best to be avoided (unless one compiler vendor
    explicitly says their product is guaranteed to be binarily compatible
    with the one from another vendor, like is the case for Intel C++
    compiler).

    Using only C types and extern "C" functions may be helpful, because C ABI
    is standardized for more platforms. I am not too sure what the C ABI says
    about things like struct padding/packing, I would probably avoid them for
    any case and use arrays instead.

    hth
    Paavo

    Comment

    • Juha Nieminen

      #3
      Re: Integrating libraries or exe's complied on different compilers

      shyam.lingegowd a@gmail.com wrote:
      If I have two c++ programs and I compile that using two different
      compilers on Unix. Is it possible for these two exe's to communicate
      with one another.
      Maybe you should first explain to us exactly how you expect two
      programs compiled with the *same* compiler to communicate with each
      other, and then maybe we will understand a bit better exactly what is
      the problem you are seeing with two programs compiled with *different*
      compilers in this regard.

      Comment

      • Ian Collins

        #4
        Re: Integrating libraries or exe's complied on different compilers

        shyam.lingegowd a@gmail.com wrote:
        Hi all,
        >
        If I have two c++ programs and I compile that using two different
        compilers on Unix. Is it possible for these two exe's to communicate
        with one another. Since the way the exe's are generated by two
        different compilers are different is it possible to communicate at
        all. Is there any alternative for the same. What about libraries
        compiled with two different compilers. If someone can give some
        feedback on the same it will be of great help.
        >
        Assuming communicate == link then the only safe way is through functions
        with extern "C" linkage.

        --
        Ian Collins

        Comment

        • red floyd

          #5
          Re: Integrating libraries or exe's complied on different compilers

          Ian Collins wrote:
          shyam.lingegowd a@gmail.com wrote:
          >Hi all,
          >>
          >If I have two c++ programs and I compile that using two different
          >compilers on Unix. Is it possible for these two exe's to communicate
          >with one another. Since the way the exe's are generated by two
          >different compilers are different is it possible to communicate at
          >all. Is there any alternative for the same. What about libraries
          >compiled with two different compilers. If someone can give some
          >feedback on the same it will be of great help.
          >>
          Assuming communicate == link then the only safe way is through functions
          with extern "C" linkage.
          >
          Even that's not safe, because they may have different ABIs into the
          Standard Library

          Comment

          • James Kanze

            #6
            Re: Integrating libraries or exe's complied on different compilers

            On Nov 15, 6:04 pm, Paavo Helde <nob...@ebi.eew rote:
            shyam.lingego.. .@gmail.com kirjutas:
            [...]
            all. Is there any alternative for the same. What about
            libraries compiled with two different compilers. If someone
            can give some
            You probably mean whether you can link together C++ libraries
            compiled by different compilers. This is undefined by the
            standard, meaning that you cannot do this portably.
            It is only possible if both compilers follow the same ABI
            (application binary interface). The ABI is typically defined
            for a certain combination of a language platform, e.g. C++ ABI
            for Linux on x86_64. I believe there are some platforms with
            standardized C++ ABI, so if both compilers follow this, they
            should be able to talk to each other.
            However, this is not enough. For example, if one library uses
            small- string optimization for std::string and the other does
            not, then any attempt to pass a std::string from one library
            to another will most probably fail miserably. This is where
            the one-definition-rule of C++ kicks in, I guess - if the
            libraries are using different std::string definitions, the
            result is undefined.
            The physical layout of std::string is part of a C++ ABI, so if
            their is a C++ ABI, there should be no problem. (On the
            platforms I work on, there isn't, and this doesn't work. In
            fact, the C++ ABI even depends on compiler options, and you
            can't necessarily link two libraries compiled with the same
            compiler. From what I understand, this is more or less
            general.)
            Using only C types and extern "C" functions may be helpful,
            because C ABI is standardized for more platforms. I am not too
            sure what the C ABI says about things like struct
            padding/packing, I would probably avoid them for any case and
            use arrays instead.
            A C ABI must define how struct's are laid out. All that I know
            do. (In particular, both Windows and Posix do, since both use
            struct's in their system ABI.) Of course, a compiler still
            might have options, or pragmas, to break this compatibility.

            --
            James Kanze (GABI Software) email:james.kan ze@gmail.com
            Conseils en informatique orientée objet/
            Beratung in objektorientier ter Datenverarbeitu ng
            9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

            Comment

            • Ian Collins

              #7
              Re: Integrating libraries or exe's complied on different compilers

              red floyd wrote:
              Ian Collins wrote:
              >shyam.lingegowd a@gmail.com wrote:
              >>Hi all,
              >>>
              >>If I have two c++ programs and I compile that using two different
              >>compilers on Unix. Is it possible for these two exe's to communicate
              >>with one another. Since the way the exe's are generated by two
              >>different compilers are different is it possible to communicate at
              >>all. Is there any alternative for the same. What about libraries
              >>compiled with two different compilers. If someone can give some
              >>feedback on the same it will be of great help.
              >>>
              >Assuming communicate == link then the only safe way is through functions
              >with extern "C" linkage.
              >>
              >
              Even that's not safe, because they may have different ABIs into the
              Standard Library
              Which systems would that apply to?

              --
              Ian Collins

              Comment

              • red floyd

                #8
                Re: Integrating libraries or exe's complied on different compilers

                Ian Collins wrote:
                red floyd wrote:
                >Ian Collins wrote:
                >>shyam.lingegowd a@gmail.com wrote:
                >>>Hi all,
                >>>>
                >>>If I have two c++ programs and I compile that using two different
                >>>compilers on Unix. Is it possible for these two exe's to communicate
                >>>with one another. Since the way the exe's are generated by two
                >>>different compilers are different is it possible to communicate at
                >>>all. Is there any alternative for the same. What about libraries
                >>>compiled with two different compilers. If someone can give some
                >>>feedback on the same it will be of great help.
                >>>>
                >>Assuming communicate == link then the only safe way is through functions
                >>with extern "C" linkage.
                >>>
                >Even that's not safe, because they may have different ABIs into the
                >Standard Library
                >
                Which systems would that apply to?
                >
                Windows? Possibly any Unix that has both a proprietary compiler and gcc?

                Comment

                • Ian Collins

                  #9
                  Re: Integrating libraries or exe's complied on different compilers

                  red floyd wrote:
                  Ian Collins wrote:
                  >red floyd wrote:
                  >>Ian Collins wrote:
                  >>>shyam.lingegowd a@gmail.com wrote:
                  >>>>Hi all,
                  >>>>>
                  >>>>If I have two c++ programs and I compile that using two different
                  >>>>compilers on Unix. Is it possible for these two exe's to communicate
                  >>>>with one another. Since the way the exe's are generated by two
                  >>>>different compilers are different is it possible to communicate at
                  >>>>all. Is there any alternative for the same. What about libraries
                  >>>>compiled with two different compilers. If someone can give some
                  >>>>feedback on the same it will be of great help.
                  >>>>>
                  >>>Assuming communicate == link then the only safe way is through
                  >>>functions
                  >>>with extern "C" linkage.
                  >>>>
                  >>Even that's not safe, because they may have different ABIs into the
                  >>Standard Library
                  >>
                  >Which systems would that apply to?
                  >>
                  Windows? Possibly any Unix that has both a proprietary compiler and gcc?
                  Unless the platform is really FUBAR, all C compilers for that platform
                  follow the platform's ABI conventions. Otherwise they wouldn't be able
                  to use any of the platform's standard headers.

                  --
                  Ian Collins

                  Comment

                  • Pete Becker

                    #10
                    Re: Integrating libraries or exe's complied on different compilers

                    On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.co msaid:
                    red floyd wrote:
                    >Ian Collins wrote:
                    >>red floyd wrote:
                    >>>Ian Collins wrote:
                    >>>>shyam.lingegowd a@gmail.com wrote:
                    >>>>>Hi all,
                    >>>>>>
                    >>>>>If I have two c++ programs and I compile that using two different
                    >>>>>compiler s on Unix. Is it possible for these two exe's to communicate
                    >>>>>with one another. Since the way the exe's are generated by two
                    >>>>>differen t compilers are different is it possible to communicate at
                    >>>>>all. Is there any alternative for the same. What about libraries
                    >>>>>compiled with two different compilers. If someone can give some
                    >>>>>feedback on the same it will be of great help.
                    >>>>>>
                    >>>>Assuming communicate == link then the only safe way is through
                    >>>>functions
                    >>>>with extern "C" linkage.
                    >>>>>
                    >>>Even that's not safe, because they may have different ABIs into the
                    >>>Standard Library
                    >>>
                    >>Which systems would that apply to?
                    >>>
                    >Windows? Possibly any Unix that has both a proprietary compiler and gcc?
                    >
                    Unless the platform is really FUBAR, all C compilers for that platform
                    follow the platform's ABI conventions. Otherwise they wouldn't be able
                    to use any of the platform's standard headers.
                    The point was that different implementations of the standard library
                    may have, for example, different implementations of std::string.

                    --
                    Pete
                    Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                    Standard C++ Library Extensions: a Tutorial and Reference
                    (www.petebecker.com/tr1book)

                    Comment

                    • Ian Collins

                      #11
                      Re: Integrating libraries or exe's complied on different compilers

                      Pete Becker wrote:
                      On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.co msaid:
                      >
                      >red floyd wrote:
                      >>Ian Collins wrote:
                      >>>red floyd wrote:
                      >>>>Ian Collins wrote:
                      >>>>>shyam.lingegowd a@gmail.com wrote:
                      >>>>>>Hi all,
                      >>>>>>>
                      >>>>>>If I have two c++ programs and I compile that using two different
                      >>>>>>compile rs on Unix. Is it possible for these two exe's to communicate
                      >>>>>>with one another. Since the way the exe's are generated by two
                      >>>>>>differe nt compilers are different is it possible to communicate at
                      >>>>>>all. Is there any alternative for the same. What about libraries
                      >>>>>>compile d with two different compilers. If someone can give some
                      >>>>>>feedbac k on the same it will be of great help.
                      >>>>>>>
                      >>>>>Assuming communicate == link then the only safe way is through
                      >>>>>function s
                      >>>>>with extern "C" linkage.
                      >>>>>>
                      >>>>Even that's not safe, because they may have different ABIs into the
                      >>>>Standard Library
                      >>>>
                      >>>Which systems would that apply to?
                      >>>>
                      >>Windows? Possibly any Unix that has both a proprietary compiler and
                      >>gcc?
                      >>
                      >Unless the platform is really FUBAR, all C compilers for that platform
                      >follow the platform's ABI conventions. Otherwise they wouldn't be able
                      >to use any of the platform's standard headers.
                      >
                      The point was that different implementations of the standard library may
                      have, for example, different implementations of std::string.
                      >
                      If the only interaction between modules is through extern "C"
                      interfaces, why would that matter?

                      --
                      Ian Collins

                      Comment

                      • Pete Becker

                        #12
                        Re: Integrating libraries or exe's complied on different compilers

                        On 2008-11-16 13:18:36 -0500, Ian Collins <ian-news@hotmail.co msaid:
                        Pete Becker wrote:
                        >On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.co msaid:
                        >>
                        >>red floyd wrote:
                        >>>Ian Collins wrote:
                        >>>>red floyd wrote:
                        >>>>>Ian Collins wrote:
                        >>>>>>shyam.lingegowd a@gmail.com wrote:
                        >>>>>>>Hi all,
                        >>>>>>>>
                        >>>>>>>If I have two c++ programs and I compile that using two different
                        >>>>>>>compiler s on Unix. Is it possible for these two exe's to communicate
                        >>>>>>>with one another. Since the way the exe's are generated by two
                        >>>>>>>differen t compilers are different is it possible to communicate at
                        >>>>>>>all. Is there any alternative for the same. What about libraries
                        >>>>>>>compil ed with two different compilers. If someone can give some
                        >>>>>>>feedba ck on the same it will be of great help.
                        >>>>>>>>
                        >>>>>>Assumin g communicate == link then the only safe way is through
                        >>>>>>functio ns
                        >>>>>>with extern "C" linkage.
                        >>>>>>>
                        >>>>>Even that's not safe, because they may have different ABIs into the
                        >>>>>Standard Library
                        >>>>>
                        >>>>Which systems would that apply to?
                        >>>>>
                        >>>Windows? Possibly any Unix that has both a proprietary compiler and
                        >>>gcc?
                        >>>
                        >>Unless the platform is really FUBAR, all C compilers for that platform
                        >>follow the platform's ABI conventions. Otherwise they wouldn't be able
                        >>to use any of the platform's standard headers.
                        >>
                        >The point was that different implementations of the standard library may
                        >have, for example, different implementations of std::string.
                        >>
                        If the only interaction between modules is through extern "C"
                        interfaces, why would that matter?
                        Because extern "C" doesn't preclude the use of C++ classes.

                        extern "C" void f(std::string*) ;

                        --
                        Pete
                        Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                        Standard C++ Library Extensions: a Tutorial and Reference
                        (www.petebecker.com/tr1book)

                        Comment

                        • red floyd

                          #13
                          Re: Integrating libraries or exe's complied on different compilers

                          Ian Collins wrote:
                          Pete Becker wrote:
                          >On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.co msaid:
                          >>
                          >>red floyd wrote:
                          >>>Ian Collins wrote:
                          >>>>red floyd wrote:
                          >>>>>Ian Collins wrote:
                          >>>>>>shyam.lingegowd a@gmail.com wrote:
                          >>>>>>>Hi all,
                          >>>>>>>>
                          >>>>>>>If I have two c++ programs and I compile that using two different
                          >>>>>>>compiler s on Unix. Is it possible for these two exe's to communicate
                          >>>>>>>with one another. Since the way the exe's are generated by two
                          >>>>>>>differen t compilers are different is it possible to communicate at
                          >>>>>>>all. Is there any alternative for the same. What about libraries
                          >>>>>>>compil ed with two different compilers. If someone can give some
                          >>>>>>>feedba ck on the same it will be of great help.
                          >>>>>>>>
                          >>>>>>Assumin g communicate == link then the only safe way is through
                          >>>>>>functio ns
                          >>>>>>with extern "C" linkage.
                          >>>>>>>
                          >>>>>Even that's not safe, because they may have different ABIs into the
                          >>>>>Standard Library
                          >>>>Which systems would that apply to?
                          >>>>>
                          >>>Windows? Possibly any Unix that has both a proprietary compiler and
                          >>>gcc?
                          >>Unless the platform is really FUBAR, all C compilers for that platform
                          >>follow the platform's ABI conventions. Otherwise they wouldn't be able
                          >>to use any of the platform's standard headers.
                          >The point was that different implementations of the standard library may
                          >have, for example, different implementations of std::string.
                          >>
                          If the only interaction between modules is through extern "C"
                          interfaces, why would that matter?
                          Because extern "C" doesn't preclude the use of new or delete. Consider:

                          /* COMPILED WITH COMPILER A */
                          extern "C" T* get_a_buffer()
                          {
                          return new T[20];
                          }


                          /* COMPILED WITH COMPILER B */
                          void f()
                          {
                          T* p = get_a_buffer();
                          /* use p */
                          delete[] p;
                          }

                          Comment

                          • Ian Collins

                            #14
                            Re: Integrating libraries or exe's complied on different compilers

                            Pete Becker wrote:
                            On 2008-11-16 13:18:36 -0500, Ian Collins <ian-news@hotmail.co msaid:
                            >
                            >Pete Becker wrote:
                            >>>
                            >>The point was that different implementations of the standard library may
                            >>have, for example, different implementations of std::string.
                            >>>
                            >If the only interaction between modules is through extern "C"
                            >interfaces, why would that matter?
                            >
                            Because extern "C" doesn't preclude the use of C++ classes.
                            >
                            extern "C" void f(std::string*) ;
                            >
                            Fair point. I always use extern "C" for functions that can be used by C.

                            --
                            Ian Collins

                            Comment

                            • Pete Becker

                              #15
                              Re: Integrating libraries or exe's complied on different compilers

                              On 2008-11-16 21:15:33 -0500, Ian Collins <ian-news@hotmail.co msaid:
                              Pete Becker wrote:
                              >On 2008-11-16 13:18:36 -0500, Ian Collins <ian-news@hotmail.co msaid:
                              >>
                              >>Pete Becker wrote:
                              >>>>
                              >>>The point was that different implementations of the standard library may
                              >>>have, for example, different implementations of std::string.
                              >>>>
                              >>If the only interaction between modules is through extern "C"
                              >>interfaces, why would that matter?
                              >>
                              >Because extern "C" doesn't preclude the use of C++ classes.
                              >>
                              >extern "C" void f(std::string*) ;
                              >>
                              Fair point. I always use extern "C" for functions that can be used by C.
                              That's certainly it's intended purpose, and primary use.

                              --
                              Pete
                              Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                              Standard C++ Library Extensions: a Tutorial and Reference
                              (www.petebecker.com/tr1book)

                              Comment

                              Working...