What is a C wrapper to wrap C++ and how do you create one? 
Author Message
 What is a C wrapper to wrap C++ and how do you create one?

I was wondering how to create a C wrapper that interfaces with C++
functions.  How would you compile and link it?  Thanks.

John Smith



Sat, 02 Apr 2005 00:35:35 GMT  
 What is a C wrapper to wrap C++ and how do you create one?

Hi,
you can make a C++ module that inside has got some  'extern "C" '
functions. Those functions can be called from C.

So you have your C code that can interact with *those* functions; and
*those* functions that interact with C++ code.

Could work?
It worked for me once.

bye
benedetto

Quote:

> I was wondering how to create a C wrapper that interfaces with C++
> functions.  How would you compile and link it?  Thanks.

> John Smith



Sat, 02 Apr 2005 02:19:32 GMT  
 What is a C wrapper to wrap C++ and how do you create one?

Quote:

> I was wondering how to create a C wrapper that interfaces with C++
> functions.  How would you compile and link it?  Thanks.

You should really ask this question in comp.lang.c++. C has no
facilities for interfacing with other languages.

Brian Rodenborn



Sat, 02 Apr 2005 03:25:18 GMT  
 What is a C wrapper to wrap C++ and how do you create one?
I tried the extern in my C++ module, but how do you call it from the C code.
Do you have to include it or is it the way you link it.

John


Quote:

> Hi,
> you can make a C++ module that inside has got some  'extern "C" '
> functions. Those functions can be called from C.

> So you have your C code that can interact with *those* functions; and
> *those* functions that interact with C++ code.

> Could work?
> It worked for me once.

> bye
> benedetto


> > I was wondering how to create a C wrapper that interfaces with C++
> > functions.  How would you compile and link it?  Thanks.

> > John Smith



Sat, 02 Apr 2005 06:52:47 GMT  
 What is a C wrapper to wrap C++ and how do you create one?

Quote:

> I tried the extern in my C++ module, but how do you call it from
> the C code. Do you have to include it or is it the way you link it.

You don't - C can't call C++ code - and you also don't toppost.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sat, 02 Apr 2005 09:37:28 GMT  
 What is a C wrapper to wrap C++ and how do you create one?
On Tue, 15 Oct 2002 01:37:28 GMT, in comp.lang.c , CBFalconer

Quote:


>> I tried the extern in my C++ module, but how do you call it from
>> the C code. Do you have to include it or is it the way you link it.

>You don't - C can't call C++ code

This is true, but not the whole story. Please ask this question again
in comp.lang.c++ where its more topical

Quote:
>- and you also don't toppost.

indeed.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>



Sun, 03 Apr 2005 03:50:47 GMT  
 What is a C wrapper to wrap C++ and how do you create one?

Quote:

> I was wondering how to create a C wrapper that interfaces with C++
> functions.  How would you compile and link it?  Thanks.

You need a header file which can be included by C, i.e. you have to use the
preprocessor to strip out anything which isn't C.  Then you need to make sure
that C++ makes sure any definitions you create can be linked to compiled C
code.

You need something like this in your header file:

#ifdef __cplusplus
extern "C"
#endif
void fred (void);

This shields the C compiler from the non-C 'extern "C"' command, but lets C++
see it, and makes sure it produces a name for linking which will be
compatible with C.  You can then write fred in C++ and call it from C.

--
Dan Ellis



Sun, 03 Apr 2005 07:10:03 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. VS.NET: Adding one .cs file to more then one project

2. Newbie: separate big .cs file into small .cs files

3. Creating verifiable dotnet assembly wrapping unmanaged C++ classes

4. Creating a managed C++ class wrapper

5. Creating C++ wrappers around C API

6. Need C++ text for non cs major course

7. System.Threading.Timer , am I doing this correctly ?

8. Wot am I doing rong??

9. Am I doing this right?

10. what am i doing wrong?

11. what am I doing wrong here?

12. What am I doing wrong?

 

 
Powered by phpBB® Forum Software