What functions are exported when build dll using Mingw gcc?

If you build a dll using Mingw g++ like:

g++ -shared -o myprogrammingnotes.dll myprogrammingnotes.cpp

If __declspec(dllexport) is not present in the source file, all functions except the entry point function(DllMain) in myprogrammingnotes.cpp will be exported by name.

If __declspec(dllexport) is present in the source file, the functions decorated by __declspec(dllexport) will be exported by name, while those functions without __declspec(dllexport) will not be exported. You can decorate DllMain with __declspec(dllexport) to export it, too.

You can also use .def to specify which functions are to be exported. Then, the functions decorated by __declspec(dllexport) plus the functions specified in .def are exported.

//mydll.def
EXPORTS  
   Sum   @2  

how to use the .def file with Mingw g++?

g++ -shared -o mydll.dll mydll.cpp mydll.def

If you want to export a function by ordinal rather than by name, you can use the NONAME attribute in .def file like

 

//mydll.def
EXPORTS  
   Sum   @2  NONAME

You can specify the ordinal for a function in .def(the number after @). The ordinal must be 1 or bigger. The least number will become the ordinal base in the image. The ordinals may be not continuous, in which case, NULL entries will occur in the export address table of the dll.

 



				
Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply