[Libssh] Enhancements proposals
Alexander Lamaison
awl03 at doc.ic.ac.uk
Sat Mar 1 10:54:34 CET 2008
> > Well I know that C is compatible with C++, but not C++ with C, unless
> by
> > using very complex technics. So I'm very curious how you would do
> your
> > stub in such a way that any native C library could compile and link
> > against it.
> Just compile with g++ a code like
> extern "C" {
> struct my_c_struct {
> myClass *c;
> };
> int C_function_do_this(struct my_c_struct *this, int arg){
> return this->c->do_this(arg);
> }
> }
>
> it works, I've tested it.
> >
> > And even if it's possible, you'll still have to design your C API...
> that's right. It will follow the external C++ api. But it's much less
> hasle than having to design the whole code with these tricks.
The biggest problem with C++ libraries is that you can only link with code
that has been compiled with the *same C++ compiler*! That often means the
same version of the compiler. The reason for this is that, unlike for C,
there is no agreed standard ABI.
Therefore, C++ libraries are usually distributed in the form of template
libraries so that they are compiled directly into the client application
rather than linked to it. Compiled C++ libraries are troublesome and rare
even in open source projects such as Linux distros.
Alex Lamaison
More information about the Libssh
mailing list