Stuck with DLL export
Posted: Sat Jul 30, 2022 10:33 am
Currently I'm stuck with MinGW and DLL exports...
We have file1.cpp:
And file2.cpp:
We compile them as:
Consider the following linking example:
It works as expected, only __declspec(dllexport) symbols are exported:

But merging files into larger object file does not work:
It gives all possible symbols exported in the DLL:

MinGW 8.1.0, tested different builds with the same result.
Any ideas how to make it work properly without using the DEF file?
We have file1.cpp:
Code: Select all
extern "C"
{
__declspec(dllexport)
int f() { return 1; }
__declspec(dllexport)
int g() { return 2; }
int k() { return 3; }
}
Code: Select all
extern "C"
{
__declspec(dllexport)
int l() { return 1; }
__declspec(dllexport)
int m() { return 2; }
int n() { return 3; }
}
Code: Select all
g++ -o file1.o -c file1.cpp -fPIC
g++ -o file2.o -c file2.cpp -fPIC
Code: Select all
g++ -o test1.dll file1.o file2.o -shared -fPIC
dumpbin /exports test1.dll

But merging files into larger object file does not work:
Code: Select all
ld -r -o file3.o file1.o file2.o
g++ -o test2.dll file3.o -shared -fPIC
dumpbin /exports test2.dll

MinGW 8.1.0, tested different builds with the same result.
Any ideas how to make it work properly without using the DEF file?
