My goal is to be able to create a C library wrapper for a Cpp library.
I have:
- libcpp.so, a dynamic library written in Cpp by someone else
- libc.so, a dynamic library written in C by me to wrap libcpp
- test.c, a simple problem to test whether it works.
My problem is that I cannot compile libc.so correctly such that I can access features from libcpp.so from test.c
Example Code:
//libc.h extern "C" void * createNetwork(); //libc.cpp #include "libc.h" #include <libcpp.h> // <- unsure about this void * createObject() { Object * foo = new Object(); void * retval = foo; return retval; } //test.c #include <stdio.h> void * createObject(); int main() { void * bar = createObject(); return 0; } I am compiling using
// COMPILE LIBC g++ -Wall -fPIC -c libc.cpp -L/opt/lib -llibcpp gcc -shared -Wl,-soname,libc.so.1 -o libc.so.1.0 *.o sudo mv libc.so.1.0 /opt/lib sudo ln -sf /opt/lib/libc.so.1.0 /opt/lib/libc.so.1 sudo ln -sf /opt/lib/libc.so.1.0 /opt/lib/libc.so // COMPILE TEST.C gcc -Wall test.c -L/opt/lib -lc -o test How do I properly include libcpp in libc?
How do I properly include libc in test.c?
Do I need header files in addition to just the dynamic libraries?
extern "C", C does not have a facility to call C++ functions.libc.h. Is it used wrongly? The only problem I see so far islibcpp.hwhich existence is not confirmed. It seems likeObjectshould be defined there. But its been years since I compiled an.soby hand. I'm not good enough to guess without an error message.