C language > Beginner questions

Build a dll without __declspec(dllexport)?

(1/2) > >>

opaque:
I forgot to add __declspec(dllexport) and write the code for the dll just like normal program. Does Pelles C support build a dll and automatically exported all functions and types from it? MinGW has this option.

http://www.mingw.org/wiki/sampledll


--- Quote ---Building and using a DLL without the dllexport/dllimport attibutes

If you pass the -no-undefined and --enable-runtime-pseudo-reloc options to the linker, you don't have to add dllimport or dllexport attributes to the source code that the DLL is made with ; all functions are imported/exported automatically by default, just like in unices.
--- End quote ---

I have successfully build a dll from my code with MinGW and program linked to it worked properly.

opaque:
When I posted this thread it's error with "Call to undefined method Akismet::setAuthor()". Fortunately, the thread was posted successfully.

frankie:
PellesC doesn't have the GCC option.
If you don't specify any exported symbol the export table in the PE file will be empty.
If you don't want modify all your DLL code you can build a DEF file with functions you want to export and relink the DLL objects adding the DEF file.
For better instructions please refer to the help for polink option /DEF:filename

opaque:

--- Quote from: frankie on April 02, 2020, 12:02:13 PM ---PellesC doesn't have the GCC option.
If you don't specify any exported symbol the export table in the PE file will be empty.
If you don't want modify all your DLL code you can build a DEF file with functions you want to export and relink the DLL objects adding the DEF file.
For better instructions please refer to the help for polink option /DEF:filename

--- End quote ---
If my code doesn't specify it does Pelles C use CDECL or STDCALL by default? I have to know this to prepare the .def file.

frankie:

--- Quote from: opaque on April 02, 2020, 05:33:23 PM ---If my code doesn't specify it does Pelles C use CDECL or STDCALL by default? I have to know this to prepare the .def file.

--- End quote ---
This is not related to the export qualifier __declspec(dllexport). This extended qualifier simply puts the address of your function in the export table of the PE executable independently from the calling convention.
You can specify the calling convention for 32bit executables on function by function basis, using the qualifiers __stdcall or __cdecl, or globally defining the default calling convention. For 64bits executables the calling convention is fixed and is the MS 64bits ABI.
The default calling convention can be set on the compiler command line with the switches /Gr and /Gz, or setting it in the IDE project options, compiler tab.
You must specify in an header file the prototype of your exported functions, eventually adding the calling convention, __stdcall or __cdecl, and include it in the modules of the executable that loads the DLL.

Navigation

[0] Message Index

[#] Next page

Go to full version