In C++, is it possible to write code / a Makefile that exports a function from a pre-written C++ file to a shared object - i.e. a DLL / SO file.
As an example, let's assume I have the follow file and function definitions.
# funcs.cpp
int add(int x, int y)
{
return x + y;
}
To make a Windows DLL, I can modify the above by changing the first line to:
extern "C" __declspec(dllexport) int add(int x, int y)
and using a Makefile containing:
#Makefile
dll: funcs.cpp
g++ -shared funcs.cpp -o output.dll
However, is this possible for the situation where I cannot modify the funcs.cpp
file. i.e. How can I package pre-written functions into a shared object please?
NOTE: This question got closed as being already answered here: Exporting functions from a DLL with dllexport
However, that question is different and it's not clear how to export to DLL without adding _declspec(dllexport) to the original cpp
file. If it's easy and I'm in fact missing something, perhaps someone could post the answer or otherwise, can the question be re-opened please?