|
From: Marcus G. <mar...@ho...> - 2002-08-02 19:30:28
|
Hello! This should be simple enough - but boy, I never though creating DLLs would be this hard... My quest: Compile a DLL and an import library using "any compiler", and the DLL should be usable by "any compiler", regardless of which compiler it was compiled with. With "any compiler", I mean any of: MinGW, Cygwin, MSVC 6.x, LCC-Win32 and Borland C++ Builder 5.x. In other words, if I compile the DLL with MSVC, I should be able to use it from MinGW, and vice versa. As a "bonus", I would also like to be able to use the DLL from e.g. Visual Basic. So far I have managed to build the DLL successfully with MSVC, LCC and Borland, and the DLL can be used from any of the three, plus Visual Basic. For your reference, the MSVC .def file looks like this: EXPORTS myfun anotherfun And the functions are declared like this when compiling the DLL: __declspec(dllexport) void __stdcall myfun( void ); __declspec(dllexport) void __stdcall anotherfun( void ); ...and when importing the DLL functions: __declspec(dllimport) void __stdcall myfun( void ); __declspec(dllimport) void __stdcall anotherfun( void ); Ok, so I tried it with MinGW, compiling my .c files with the -mdll option, and using the 'dllwrap' tool for linking: dllwrap --dllname myapi.dll --output-lib libmyapi.a $(DLLOBJS) $(LINKLIBS) Result: DLL can be used by MinGW, but not by MSVC. MSVC DLL can not be used by MinGW. ...so I added the -k switch: dllwrap -k --dllname myapi.dll --output-lib libmyapi.a $(DLLOBJS) $(LINKLIBS) Result: DLL can NOT be used by MinGW, nor by MSVC. BUT, the MSVC DLL can be used by MinGW. Conclusion: the -k switch creates a correct (MSVC compatible) import library, but does not produce a correct DLL. I have tried so many combinations of dlltool, dllwrap, __stdcall, extern, __decpspec(dllexport) etc, etc, that I have lost track. Surely someone must have had success with this in the past, and I guess it's simpler than I can imagine - but please, could someone help me here? PS. Please CC to mar...@ho..., since I don't seem to get all the mailing list mails to my box (only 10 mails in the last 14 days?). |