brimworks / lua-zlib

Simple streaming interface to zlib for Lua.
273 stars 111 forks source link

Unable to load #23

Closed daurnimator closed 9 years ago

daurnimator commented 9 years ago

I compiled/installed via luarocks:

$ sudo luarocks install lua-zlib
Installing https://rocks.moonscript.org/lua-zlib-0.3-1.rockspec...
Using https://rocks.moonscript.org/lua-zlib-0.3-1.rockspec... switching to 'build' mode
Cloning into 'lua-zlib'...
remote: Counting objects: 17, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 17 (delta 0), reused 11 (delta 0)
Receiving objects: 100% (17/17), 11.82 KiB | 0 bytes/s, done.
Checking connectivity... done.
Note: checking out 'c0014bcbc4c3fd65ba3519b10965f0c184c1a059'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

gcc -O2 -fPIC -I/usr/include -c lua_zlib.c -o lua_zlib.o
gcc -shared -o zlib.so -L/usr/lib lua_zlib.o
Updating manifest for /usr/lib/luarocks/rocks-5.2
lua-zlib 0.3-1 is now built and installed in /usr (license: MIT)

However, when trying to run (e.g, via lua -lzlib), I get:

/usr/lib/lua/5.2/zlib.so: undefined symbol: inflate

The fix seems to be renaming the shared object, e.g. to lua-zlib.so. I assume this is due to the dynamic linker getting confused?

brimworks commented 9 years ago

The inflate symbol should come from libz.so. Perhaps the problem is when linking zlib.so, you need to pass the -lz flag to the linker to tell it that the libz.so is NEEDED. Perhaps this means the rockspec needs to be updated to tell the linker to pass the -lz flag, but I'm no expert in rockspec's, so I'm not sure how to do that. Perhaps if you just use make to do the build all will be well?

You can use objdump -x zlib.so to see if the appropriate NEEDED field exists in the elf file.

If you know how to update the rockspec, please send me a patch.

Thanks, -Brian

daurnimator commented 9 years ago

The inflate symbol should come from libz.so. Perhaps the problem is when linking zlib.so, you need to pass the -lz flag to the linker to tell it that the libz.so is NEEDED.

That seems to work.

Perhaps this means the rockspec needs to be updated to tell the linker to pass the -lz flag, but I'm no expert in rockspec's, so I'm not sure how to do that.

Add 'z' to the libraries array, so instead of

    zlib = "lua_zlib.c"`

Have:

    zlib = {
        sources = { "lua_zlib.c" };
        libraries = { "z" },
    };
brimworks commented 9 years ago

Okay, I think this is fixed (and I finally got around to using luarocks a bit).

luarocks install lua-zlib will install the latest which has the fix (0.4-1 version).

On my Mac, I can now properly see the NEEDED field is set for libz:

otool -L /usr/local/lib/lua/5.2/zlib.so

/usr/local/lib/lua/5.2/zlib.so: /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 283.0.0)

Thanks, -Brian

daurnimator commented 9 years ago

luarocks install lua-zlib will install the latest which has the fix (0.4-1 version).

The new rockspec has not been uploaded to moonrocks yet? https://rocks.moonscript.org/search?q=lua-zlib

It appears that @guilhem currently has ownership over that rock, will you (@brimworks) take that over?

brimworks commented 9 years ago

It is there: https://rocks.moonscript.org/search?q=lua-zlib&non_root=on

I would like to take ownership of this rock, just not sure how I should do that.

Thanks, -Brian

daurnimator commented 9 years ago

It is there: https://rocks.moonscript.org/search?q=lua-zlib&non_root=on

Ah ha, I forgot to include non-root.

I would like to take ownership of this rock, just not sure how I should do that.

You can to poke @leafo and/or @hishamhm who will fix it up for you. Otherwise I think if @guilhem withdraws his version from the root manifest, you can then promote yours.

guilhem commented 9 years ago

I can manage it next week if you are asking gently ;)

leafo commented 9 years ago

I can transfer it right now now, sound good @brimworks

brimworks commented 9 years ago

Thanks! No big rush :).

leafo commented 9 years ago

Alright, good to go: http://rocks.moonscript.org/modules/brimworks/lua-zlib

I also copied the older versions into your copy of the module

guilhem commented 9 years ago

I deleted mine for less confusion