[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Integrating libraries or exe's complied on different compilers

shyam.lingegowda

11/15/2008 4:30:00 PM

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
14 Answers

Paavo Helde

11/15/2008 5:05:00 PM

0

shyam.lingegowda@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

Juha Nieminen

11/15/2008 5:23:00 PM

0

shyam.lingegowda@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.

Ian Collins

11/15/2008 8:40:00 PM

0

shyam.lingegowda@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

red floyd

11/15/2008 10:36:00 PM

0

Ian Collins wrote:
> shyam.lingegowda@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

James Kanze

11/16/2008 12:14:00 AM

0

On Nov 15, 6:04 pm, Paavo Helde <nob...@ebi.ee> wrote:
> 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.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Ian Collins

11/16/2008 12:51:00 AM

0

red floyd wrote:
> Ian Collins wrote:
>> shyam.lingegowda@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

red floyd

11/16/2008 7:29:00 AM

0

Ian Collins wrote:
> red floyd wrote:
>> Ian Collins wrote:
>>> shyam.lingegowda@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?

Ian Collins

11/16/2008 7:39:00 AM

0

red floyd wrote:
> Ian Collins wrote:
>> red floyd wrote:
>>> Ian Collins wrote:
>>>> shyam.lingegowda@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

Pete Becker

11/16/2008 1:25:00 PM

0

On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.com> said:

> red floyd wrote:
>> Ian Collins wrote:
>>> red floyd wrote:
>>>> Ian Collins wrote:
>>>>> shyam.lingegowda@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.

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)

Ian Collins

11/16/2008 6:19:00 PM

0

Pete Becker wrote:
> On 2008-11-16 02:38:53 -0500, Ian Collins <ian-news@hotmail.com> said:
>
>> red floyd wrote:
>>> Ian Collins wrote:
>>>> red floyd wrote:
>>>>> Ian Collins wrote:
>>>>>> shyam.lingegowda@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.
>
> 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