I have a .lib file, source code of which I don't have.
I need an exported function from it, but I'm writing in C, and the function is C++ name-mangled. I can't write extern "C", because I don't have the source code.
How do I link mangled function without source code and switching to C++?
Make C++ wrapper:
wrapper.cpp:
#include "3rdparty.hpp"
extern "C" int foo(int a, int b)
{
return third_party::secret_function(a, b);
}
consumer.c:
extern int foo(int, int);
// ...
Build: (e.g. with GCC)
g++ -o wrapper.o wrapper.cpp
gcc -o consumer.o consumer.c
g++ -o program consumer.o wrapper.o -l3rdparty
Write your own C++ wrapper over those functions and declare your wrapper functions with extern "C".
I'm not aware of any other way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With