Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mixing compiler

I am wondering if it is possible to link a c++ program compiled with gcc4.2 with a shared c++ library that is compiled in a later version like gcc4.5.

I've tried to do this, but have run into some different kind of problems. When compiling the shared library gcc5.3 I get a message saying:

*"malloc: error for object 0x7fff707d2500: pointer being freed was not allocated set a breakpoint in malloc_error_break to debug"*.

If I try to compile the shared library with gcc4.6 I get really strange behaviour. The std::stringstream class is not working correctly. The resulting string is empty after writing to the stream.

Is it possible to do this? Or am I trying something that is impossible? I was hoping that this was possible since I'm linking the lib dynamically. Btw I'm running on MacOSX.

BR

like image 798
user499986 Avatar asked Jul 04 '11 20:07

user499986


People also ask

What does mix compile do?

It simply runs the compilers registered in your project and returns a tuple with the compilation status and a list of diagnostics. Before compiling code, it loads the code in all dependencies and perform a series of checks to ensure the project is up to date.

Can I run C code in C++?

Accessing C Code from Within C++ SourceAll C++ compilers also support C linkage, for some compatible C compiler. When you need to access a function compiled with C linkage (for example, a function compiled by the C compiler, or a function written in assembler), declare the function to have C linkage.


1 Answers

Beginning with gcc 3.0, g++ follows the Itanium ABI, so in theory there should be no problem. However, g++ 4.2 has CXXABI_1.3.1 whereas g++ 4.5 has CXXABI_1.3.4 (see here). Therefore I'd be careful. One does not bump up revision numbers if there are no differences.

Further, the glibc++ has gone through 5 revisions between those versions, which may be one reason why you see std::stringstream do funny things.

Lastly, there exist many config options (such as for example making strings fully dynamic or not) which affect the behaviour and compatibility of the standard library directly. Given two (random, unknown) builds, you cannot even know that they have the same config options.

like image 80
Damon Avatar answered Sep 19 '22 15:09

Damon