P
Pallav singh
Hi All,
How do I call a C++ function from C?
Thanks
Pallav
How do I call a C++ function from C?
Thanks
Pallav
Pallav said:Hi All,
How do I call a C++ function from C?
Thanks
Pallav
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Is the function located in an external library?
The easiest way to do this would be to compile a separate module as C++
which provides wrappers for the C++ functions, exporting them as "extern
C ...". Then you can link your C code to those functions and don't have
to worry about name decoration issues.
$ g++ -g file1.cc file2.c
: In function `_Z2cci':
: undefined reference to `func(int)'
collect2: ld returned 1 exit status
Another guess: did you really create "file2.c" or is it "file2.C" ?
I remember vaguely this made a difference for the assumed programming
language for gcc.
MiB
can we call member functions (incl. virtual functions) of Class in C++
from C ?
On Mar 29, 3:27 pm, Robert Hairgrove <[email protected]>
wrote:> Pallav singh wrote:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i am getting following error
file1.cc
extern "C" void func(int );
void func(int i)
{
printf(" C++ function called %d \n", i);
}
file2.c
#include <stdio.h>
void func(int);
void cc(int i)
{ func(i); }
int main()
{
cc(1);
return 0;
}
$ g++ -g file1.cc file2.c
: In function `_Z2cci':
: undefined reference to `func(int)'
collect2: ld returned 1 exit status
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.