[Luarocks-developers] luarocks on cygwin problems
David Manura
dm.lua at math2.org
Sat Aug 16 21:27:30 GMT+2 2008
I'm trying out LuaRocks (latest snapshot) under Cygwin (without
mingw). I ran into some of the same issues in the discussion
http://lists.luaforge.net/pipermail/luarocks-developers/2008-May/000637.html
.
That is, I get compile errors like
$ luarocks install lbase64
Installing http://luarocks.luaforge.net/rocks/lbase64-20070628-1.src.rock...
...
cc -I/usr/local/include -c lbase64.c -o lbase64.o
ld -shared -o base64.dll lbase64.o
lbase64.o:lbase64.c:(.text+0x83): undefined reference to `luaL_addlstring'
lbase64.o:lbase64.c:(.text+0xa8): undefined reference to `luaL_checklstring'
...
The problem is two-fold. First, to ensure the Lua library can be
linked, the "-llua" apparently needs to be appended to the link like
this:
ld -shared -o base64.dll lbase64.o -llua
That can be achieved by appending 'libraries = {"lua"}' to
build.modules.base64 in the rockspec:
build = {
type = "module",
modules = {
base64 = {
"lbase64.c",
libraries = {"lua"} --added
}
},
}
For other Libraries using type = "make", the "-llua" needs to be added
to the Makefile rules:
$(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS) -llua
(How can we avoid editing the .rockspec or Makefile here?)
This then results in new linker errors:
/usr/local/lib/liblua.a(lapi.o):lapi.c:(.text+0xb0a): undefined
reference to `strlen'
...
/usr/local/lib/liblua.a(llex.o):llex.c:(.text+0xdbf): undefined
reference to `_imp___ctype_'
/usr/local/lib/liblua.a(lcode.o):lcode.c:(.text+0x1232): undefined
reference to `floor'
...
This can be resolved by adding the "-lm -lc -lcygwin" linker options,
but it's simpler to replace the command "ld" with "gcc". More
generally, just force LuaRocks to have the same behavior as in Linux
via these options in config.lua (as already suggested in the previous
discussion):
variables.CC = "gcc"
variables.LD = "gcc"
variables.LIBFLAG = "-shared"
This would make sense since I compiled Lua itself under Cygwin using
"make linux".
The "-llua" still is needed though under Cygwin. I think this is
related to differences in Linux shared libraries and Windows DLLs
(used to implement Cygwin shared libraries). Mainly, all the symbols
must be resolved at compile time:
http://wiki.osdev.org/Cygwin_Issues#DLL
http://www.cygwin.com/ml/cygwin/2006-02/msg00651.html
Adding -llua on non-Cygwin builds probably doesn't hurt. However, I
think that would be easy to miss by anyone not running Cygwin (i.e. it
would be brittle) and so should instead be under control of LuaRocks
in some way.
More information about the Luarocks-developers
mailing list