tags:

views:

15

answers:

1

Dear all,

I have a set of software library modules which are developed in c++. So, I use g++ to compile my software.

This has to be used by various existing applications which are written in C and compiled with gcc.

When the other teams used g++ to compile their code, they started getting lot of compiler errors due to strict type checking rules of c++. This broke their applications. Worse still, they are using some 3rd party library code, which cannot be compiled using g++.

if they use gcc, then there are linker errors (unresolved symbols).

so, my question is... "Is there a way for my library code to be linked with their applications, without changing the respective compilers? That is, i still have to use g++, since i use classes/objects heavily in my code, and they have no choice of using g++, which will break their application?".

Thank you for kind help.

regards, Ravindra

A: 

One of the problems you may be experiencing could be the result of different versions of g++ having different ABI formats. at very least, don't expect versions of G++ prior to 4.1 to work with code compiled with 4.1 or later.

Intermingling C and C++ requires that the C++ code all export a C compatible interface. This is done by declaring free functions (cannot be used on classes) with the extern "C" specifier. (some notes on the c++ faq lite_

extern "C" {
  #include "c_language_headers.h"

  int c_accessible_function(int);

  struct c_accessible_datatype { };
}
TokenMacGuy
Hi TokenMacGuy,
Ravindranath
Thank you for the quick response. I am already doing this part
Ravindranath
I am using #ifdef __cplusplus extern "C" #endif part. But inspite of this, I was under the impression that both the modules (the c code that calls and the c++ library) should be compiled with g++ only. Correct me, if I am wrong.
Ravindranath
Ravindranath
the code that has the main() function is the c code, which is going to be compiled using gcc. My library has to be compiled with g++, since I am using classes. However, I am providing a wrapper interface via extern "C".
Ravindranath
OK, does it mean, I can let my library users "compile" using gcc, but when they link, should they use g++ ?
Ravindranath