2

I am trying to find every library that is actually needed to run a lua script that requires torch libraries

test.lua:

#!/usr/bin/env lua

print "Welcome to LUA"
print('_VERSION = ' .. _VERSION)
require("nn") -- this loads torch nn libraries to be further used in the code
print "Load pass"

Output:

Welcome to LUA
_VERSION = Lua 5.1
Load pass

When I use

lld ./lua
# or
lld ./lua test.lua

I get the following output:

ldd ./lua ../../../bin/test.lua
    linux-vdso.so.1 =>  (0x00007ffdba77d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f160dd3e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f160db3a000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f160d8f3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f160d52a000)
    /lib64/ld-linux-x86-64.so.2 (0x00005580e2ebd000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f160d301000)
../../../bin/test.lua:
    not a dynamic executable

Obviously the libraries used by torch nn are not displayed here. We only see the necessary libraries to the "lua" program

If make the test.lua an executable file and I run ldd ./test.lua, I get the following output

ldd ./test.lua 
    not a dynamic executable

How to check what libraries (or .so) are linked when I run a interpreted language binary and its script? (in Lua and in Python)

yugr
  • 19,769
  • 3
  • 51
  • 96
nico
  • 1,136
  • 1
  • 15
  • 33
  • See also http://stackoverflow.com/questions/19767135/how-can-i-list-modules-and-check-functions-exist-at-the-command-line. – lhf Nov 29 '16 at 13:06

2 Answers2

5

You can use LD_DEBUG:

$ LD_DEBUG=all python tmp.py 2>&1 | grep 'generating link map'
3358:   file=libpthread.so.0 [0];  generating link map
3358:   file=libc.so.6 [0];  generating link map
3358:   file=libdl.so.2 [0];  generating link map
3358:   file=libutil.so.1 [0];  generating link map
3358:   file=libz.so.1 [0];  generating link map
3358:   file=libm.so.6 [0];  generating link map

Keep in mind that if your app only loads library on particular event, you may not see it during default run.

yugr
  • 19,769
  • 3
  • 51
  • 96
1

Most probably Lua is loading nn dynamically. It looks for nn in LUA_CPATH or package.cpath.

One way to find which libraries are being required is to redefine require:

local real_require=require
function require(x)
    print(x,package.searchpath(x,package.cpath))
    return real_require(x)
end
lhf
  • 70,581
  • 9
  • 108
  • 149
  • I agree with you. It is being loaded dynamically from LUA_PATH (nn was a bad example as it did not have a matching .so). But it performs several other `require ("libraries")` that have corresponding .so. Those libraries that are being loaded from LUA_CPATH, but I want to know exactly which of those libraries are loaded. Is it possible to check the dynamically linked libraries? If so, how do I do this on an interpreted script? – nico Nov 28 '16 at 18:01
  • I got a problem where it complains on the searchpath function. Does package.searchpath requires any "includes" – nico Nov 29 '16 at 18:39
  • 2
    @ElectricGoat, you need Lua 5.2 or later for that, sorry. – lhf Nov 29 '16 at 19:40