Re: call c++ function from c
- From: "Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx>
- Date: Sat, 11 Aug 2007 00:02:11 GMT
Marcin Wolcendorf <wolcendo@xxxxxxxxxxxxxx> wrote in message
news:f9ho4k$lce$1@xxxxxxxxxxxxxxxxxxxxxx
falk.von.roetel@xxxxxx wrote:
I have the problem to call a c++ funtion in a C project. I have a
header file from the cpp file. In the header file the function is
decleared "int GetHostIPAddresses(ini i);". I inlcude the header file
in the c file and call the function GetHostIPAddresses(1);. But the
linker doesn't found the function. Can someone give me a hint what is
wrong.
Well, other explaind why it doesn't work pretty well, so I'll skip this
part.
If you want to use C++ function in C and you don't want to change C++
code, add a wrapper layer. Decalre function in C++ that calls your
intended function- it should look something like this:
foo() - your C++ function.
In .cpp file:
extern "C" foo_for_C()
{ return foo()}
In .h file:
#ifdef __cplusplus
extern "C" {
#endif
foo_for_c();
#ifdef __cplusplus
}
#endif
Well, looky there, an actual correct answer in this newsgroup. This
question has come up several times here, and certain people have once
again chosen to not only be presumably off-topic but just completely
wrong as well. They were affirmatively corrected several times
before, but apparently they are uneducable.
And I'm quite sure, quite worthless as programmers or for any
type of positive contribution to the human race. They are the garbage
that lie to get a job, then dog it for as long as they can with a constant
stream of excuses, lies, abuse, and obnoxious behavior in lieu of
actually ever writing any type of useful software.
In other words, the epitomy of how most employers are forced
to view "software engineers" due to long painful experience...
---
William Ernest Reid
.
- Follow-Ups:
- Re: call c++ function from c
- From: Chris Torek
- Re: call c++ function from c
- References:
- call c++ function from c
- From: falk . von . roetel
- Re: call c++ function from c
- From: Marcin Wolcendorf
- call c++ function from c
- Prev by Date: Re: Malcolm's new book - Chapter 1 review
- Next by Date: Re: islam ??
- Previous by thread: Re: call c++ function from c
- Next by thread: Re: call c++ function from c
- Index(es):
Relevant Pages
|