how to call C++ from C?
From: Digital Puer (digital_puer_at_hotjail.comet)
Date: 01/10/04
- Next message: Arthur J. O'Dwyer: "(way OT) Re: [C++] Casting void* pointers within different scope"
- Previous message: Andrey Tarasevich: "Re: program that compiles in C but not in C++?"
- Next in thread: Kevin Goodsell: "Re: how to call C++ from C?"
- Reply: Kevin Goodsell: "Re: how to call C++ from C?"
- Reply: Malcolm: "Re: how to call C++ from C?"
- Reply: Martijn Lievaart: "Re: how to call C++ from C?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 09 Jan 2004 16:28:17 -0800
I have some C++ code that I would like to call from within a C program
(main() is within the C code). How do I go about doing this portably?
I know that I can find the mangled name of the C++ functions, but
this is kind of weird.
I am using gcc and g++ on Linux, if that matters.
Here is an example of what I'm doing:
---------------------------------------------------
a.c:
---------------------------------------------------
#include "b.h"
int main()
{
foo();
}
---------------------------------------------------
b.h
---------------------------------------------------
int foo();
---------------------------------------------------
b.cpp
---------------------------------------------------
#include <map>
int foo()
{
map<int, int> m;
}
---------------------------------------------------
Makefile
---------------------------------------------------
a.out: a.o b.o
g++ a.o b.o
a.o: a.c
gcc -c a.c
b.o: b.cpp
g++ -c b.cpp
- Next message: Arthur J. O'Dwyer: "(way OT) Re: [C++] Casting void* pointers within different scope"
- Previous message: Andrey Tarasevich: "Re: program that compiles in C but not in C++?"
- Next in thread: Kevin Goodsell: "Re: how to call C++ from C?"
- Reply: Kevin Goodsell: "Re: how to call C++ from C?"
- Reply: Malcolm: "Re: how to call C++ from C?"
- Reply: Martijn Lievaart: "Re: how to call C++ from C?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|