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.