lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2011/7/25 Yutaka Ueno <uenoyt@ni.aist.go.jp>:
> Does anyone tried to use flexdll for lua?
> flexdll is an alternative DLL maker for mingw/cygwin and comes with
> a special version of dlopen()/dlsym() library. The home page tells
> that it was developed for OCaml to support the c binray modules.
>
> I was thinking to use it for my program, which statically
> links Lua interpreter, and takes c-binray modules.
> My problem is making a c-binary module as a DLL in MinGW,
> where gnu-ld always needs all symbols resolved. I have tried
> to build a DLL that use functions defined in a exe-file of
> my c application program (ANSI C), but failed.
> The flexdll seems to release the restriction.
> I think, MSVC linker and Borland C compiler-linker
> are ok to build a DLL with undefined symbols.
> Of cause, gnu-ld in Linux has no restriction.
>
> Any suggestions are appreciated.
> thank you in advance.

I can't talk about flexdll, but I can give you more insight about the
limitation with regular DLLs.

The limitation is in the Windows DLL file format (and the default
Windows DLL loader), not in one perticular linker. Imported symbols
are associated to a module name in addition to the symbol name itself
(e.g. "CreateFile in kernel32.dll", not simply "CreateFile"). This
implies that when you generate your binary modules, and the Lua C API
functions are declared as import, the linker must know the module name
from which to load them. This is usually "lua51.dll" (or something
similar). AFAIK you cannot NOT specify a module name.

What you can do when you statically link Lua in an executable is
export the symbols from the executable (they use the same file format
as DLLs), and then either use the executable name as import module
name for your binary modules, or create a forwarding (codeless) DLL
that redirects calls to the executable.