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