Mickey Shine
Mickey Shine

Reputation: 12539

How to compile a c++ program into shared library, and load it from a c program?

I am using gnu c compiler on centos 6, and the c program loads the shared library in the code dynamically.

Upvotes: 2

Views: 323

Answers (1)

chrisaycock
chrisaycock

Reputation: 37930

You must declare your function to be useable in C:

extern "C" void foo(int x, char y);

Note that you can't do overloading or any of the other features that C++ gives you. (This is because of name mangling.)

Upvotes: 2

Related Questions