Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing C/C++ Libraries

Is it possible for gcc to link against a library that was created with Visual C++? If so, are there any conflicts/problems that might arise from doing so?

like image 837
Landon Avatar asked Sep 04 '08 04:09

Landon


People also ask

Is it OK to mix C and C++?

The C++ language provides mechanisms for mixing code that is compiled by compatible C and C++ compilers in the same program. You can experience varying degrees of success as you port such code to different platforms and compilers.

How do I combine C and C++ codes?

Just declare the C++ function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code: extern "C" void f(int);

Can C++ use all C libraries?

Yes - C++ can use C libraries.

Can I compile C code in C++ compiler?

Due to this, development tools for the two languages (such as IDEs and compilers) are often integrated into a single product, with the programmer able to specify C or C++ as their source language. However, C is not a subset of C++, and nontrivial C programs will not compile as C++ code without modification.


1 Answers

Some of the comments in the answers here are slightly too generalistic.

Whilst no, in the specific case mentioned gcc binaries won't link with a VC++ library (AFAIK). The actual means of interlinking code/libraries is a question of the ABI standard being used.

An increasingly common standard in the embedded world is the EABI (or ARM ABI) standard (based on work done during Itanium development http://www.codesourcery.com/cxx-abi/). If compilers are EABI compliant they can produce executables and libraries which will work with each other. An example of multiple toolchains working together is ARM's RVCT compiler which produces binaries which will work with GCC ARM ABI binaries.

(The code sourcery link is down at the moment but can be google cached)

like image 71
tonylo Avatar answered Oct 26 '22 04:10

tonylo