> -----Original Message----- > From: owner-jed-users-l@xxxxxxxxxxxxxx > [mailto:owner-jed-users-l@xxxxxxxxxxxxxx] On Behalf Of John E. Davis > Sent: sabato 5 marzo 2005 16.09 > To: jed-users@xxxxxxxxxxx; jed-users@xxxxxxxxxxx > Subject: Re: Installer for WJED available > > The source contains two types of symbols: those that are in > the public API with names of the form SL* and those that are > private to the library _pSL*. Would both need to be give the > __declspec(dllexport) attribute? Only symbols declared with __declspec(dllexport) (or declared in .def) will be exported by the dll. Trying to reference a symbol without export from a program (or external dll) will cause an undefined reference when linking. (I have mixed feelings about this feature: on one side, it helps to clearly define the library interface, but I would like a way to say "export everything"). It seems that something like this can also be done on ELF systems. info gcc documents an __attribute__(visibility(hidden)). Or we can create linker maps (almost only on linux). E.g: jed calls _pSLsnprintf (if HAVE_SNPRINTF is not defined). But this function is not present in slang.h, but in _slang.h. Three things can be done: 1) Make _pSLsnprintf a full public function (maybe renaming it to Slsnprintf). 2) Add _declspec(dllexport) to declaration in _slang.h (this way it will be exported). 3) Do not call it from outside. I vote for 1). > How does this work? Is it sufficient to do something like: > > #ifdef __WIN32__ > #define EXPORT __declspec(dllexport) > #else > #define EXPORT > #endif > > and then change declarations in slang.h to, e.g., > > EXPORT int SLang_get_error (); > > ?? Or must this be put in the source code where > SLang_get_error is actually defined? And should the private > symbols (_pSL*) get the same treatment? I will probably move > some such as _pSLvsnprintf to the public API. > Not this simple, but not a lot harder :)) The __declspec(dllexport) should be attached to symbol *declaration*, i.e. in slang.h. The problem is that __declspec(dllexport) is needed only when compiling Slang, but MUST NOT be present when compiling external programs including slang.h (as those would pretend to export that symbol, and fail). The standard solution is using something like: #ifdef SLANG_DLL #define SLANG_EXPORT __declspec(dllexport) #else #define SLANG_EXPORT __declspec(dllimport) #endif And define (maybe using -D compiler switch) SLANG_DLL when compiling the library. A problem with this solution is that you can't use __declspec(dllimport) while compiling againt the static library, so you need a way to tell slang.h that you are compiling for static linking, and so SLANG_EXPORT should be defined to empty string (the .def method doesn't have this problem). The big problem is that the address of a global variable defined in a dll is NOT constant. So it can't be used to initialize a global variable at compile time (Linux and almost every other system I can think that supports dynamic objects can do this...). This is why we need some changes to Jed. But well, I feel better writing code than writing in (some sort of) english, I have prepared a crude patch to be able to build a dll. For slang I have: 1) added a target 'dll' to makefile.all, it is dumped to Makefile if mkmake gets a DLL parameter. 2) added file startup.c for DllMain function. 3) moved _pSLvsnprintf() and _pSLsnprintf() declarations to slang.h (I have still not renamed those). 4) added SLANG_EXPORT to slang.h 5) added some 'extern' declarations to some functions in slang.h (most already have it). 6) added a big big hack to automagically declare symbols using SLANG_EXPORT. The big hack is very very ugly, but allows me to keep this patch very small. Surely this should be made the right way: I simply #define extern as 'extern SLANG_EXPORT', exploiting the fact that almost every symbol already has an 'extern' in front, this gives me a SLANG_EXPORT for free. For Jed (all because of slang global variables referenced in initializations): 1) tt_Ignore_Beep, tt_Use_Ansi_Colors, tt_Term_Cannot_Scroll and tt_Ignore_Beep are initialized to NULL, and assigned to &SLtt_* in main_initialize(). 2) Intrinsic variables pointing directly to slang variables ("DISPLAY_EIGHT_BIT" and "LAST_CHAR") removed from Jed_Variables[], and added run-time. 3) removed declarations of _pSLvsnprintf() and _pSLsnprintf() from misc.h (now are defined in slang.h). 4) added SLANG_EXPORT to local import of _pSLw32_Hstdin in w32cons.c and win32.c. Note: this diff comes with changes missing from jed to support the renaming of 'private' functions to _pSL*. I have build jed B0.99.17-70 with a dll version of slang, both console and windowed, and used it to check and clean up the attached patched. I have also built slsh, and prepared an experimental jed installer that uses the dll (I will put this version on my page tonight). > What changes would be required to makefile.all to create such a dll? These are the easier part... Take a look at the diff (these are not polished as they ought to be, but with some cosmetic changes it would be ok). Later, Dino
Attachment:
slang-dll-support.diff
Description: Binary data
Attachment:
jed-slang-as-dll-support.diff
Description: Binary data