Re: DLL exporting with __declspec or .DEF file?
sjnorris123@yahoo.com wrote:
I've been reading several posts, MSDN articles and VC Help but it's
still not clear to me whether or not an EXE has to be recompiled if an
implicitly linked DLL changes.
Currently, all of our applications are statically linked and we are
considering converting our library code to a DLL. From what I've read,
implicit linking seems to be the simpliest to implement but I'm
concerned about the statements I've read that says if you are using
__declspec to export/import and you change the DLL then you have to
recompile the EXE's that implicitly link to the export lib.
I wish you could provide a URL, so I could address the statement itself.
Now, you need to recompile your app when the interface changes in a way that
the expected interface is not provided anymore. This is the abstract.
This means:
- If you have datatypes declared and their binary layout changes (i.e. order
or size), dependent code (which might also be in client libs) needs to be
recompiled.
- If you change the signature of a function (return type, parameter types,
numbers or order), the same applies.
- If you remove (or move/rename) a function, code that uses it will need to
be changed and recompiled.
- If you add a function or structure, old code won't use it but it will keep
on working.
Other than what was suggested with the handling of dllimport/dllexport via
the preprocessor, you should also give your DLL a version (part of the
filename) and increase that version whenever you make an incompatible
change. Some would say that even when you add something you should increase
the version, because code compiled against the newer API won't work with a
slightly older version.
Also, use #pragma comment(lib, ..) to automatically select the right version
of the lib to link. This means assembling the name from a base, a version
and a debug/release tag. Note for C++: here, you should also include the
compiler ABI.
We are
using purely C code, no C++ and the testing that I've done seems to
indicate that additional functions can be exported from the DLL and the
EXE's run fine without recompiling. Is this just by shear luck?
No, except when using ordinals, as was already mentioned.
I guess I'm trying to understand if using __declspec exports by name or
ordinal and if using __declspec is the way we should go or if we should
be using the .DEF method, though this method seems to carry a high
maintenance overhead.
There is exactly one case where I use DEF files, and that is when creating
plugins. There, the DEF files are auto-generated though.
Uli