Trouble running the hello world application

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble running the hello world application

Robert Vasek
Hello,

I'm having trouble running luabind's hello world application
(http://www.rasterbar.com/products/luabind/docs.html#hello-world).
My source code including info about my OS, versions and the error
message: http://pastebin.com/MDt7hzdc
I have luabind installed from Debian testing repos (version 0.9.1).

btw I'm a complete newbie in Lua...
Also, when I replace the greet() call with:
print(f)

the result is:
$ lua test.lua
nil

Don't know if the result should be something different, but my 2 cents
would be on that it doesn't load the library.

Can anyone help me out? Thanks in advance.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Willi Schinmeyer
Looking at some old code of mine, init() should be called luaopen_init().

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Robert Vasek
On 13.09.2012 09:16, Willi Schinmeyer wrote:

> Looking at some old code of mine, init() should be called
> luaopen_init().
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

Nope, still doesn't work. I thought it doesn't matter what is the
function called since the name of the function is passed to
package.loadlib as the 2nd argument so it always knows what to call. And
I also forgot to call the init (now luaopen_init) function so now it
should look like this:

     2 local f = package.loadlib(path, "luaopen_init")
     3 f()

but since f is nil, as a result of not loading the library for some
reason, it gives me this error:
$ lua test.lua
lua: test.lua:3: attempt to call local 'f' (a nil value)
stack traceback:
        test.lua:3: in main chunk
        [C]: ?

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Willi Schinmeyer
Right, seems like I didn't read carefully enough. I never used
package.loadlib, I used require. This is 5.1 we're talking about, right?
I don't have any experience with 5.2.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Robert Vasek
On 13.09.2012 13:19, Willi Schinmeyer wrote:

> Right, seems like I didn't read carefully enough. I never used
> package.loadlib, I used require. This is 5.1 we're talking about,
> right?
> I don't have any experience with 5.2.
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions
> will include endpoint security, mobile security and the latest in
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

Yes, specifically 5.1.5 (I've mentioned it in the link
http://pastebin.com/MDt7hzdc in my first post). Can I use require to
load dynamic libraries?

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: *** GMX Spamverdacht *** Re: Trouble running the hello world application

Dennis Schridde
Am Donnerstag, 13. September 2012, 13:38:51 schrieb [hidden email]:
> Yes, specifically 5.1.5 (I've mentioned it in the link
> http://pastebin.com/MDt7hzdc in my first post). Can I use require to
> load dynamic libraries?
http://www.lua.org/manual/5.2/manual.html#pdf-package.searchers

You can also do it via package.preload, which is what I do. Like this:
        lua_getglobal(L, "package");
        lua_getfield(L, -1, "preload");
        lua_pushcfunction(L, init_function);
        lua_setfield(L, -2, name); // package.preload[name] = init_function
        lua_pop(L, 2); // pop(package.preload, package)

--Dennis
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Willi Schinmeyer
In reply to this post by Robert Vasek
> Can I use require to load dynamic libraries?
Works on windows anyway. Not sure which directories are searched on
Linux, but it should work somehow.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Tom McCubbin-2
In linux it uses the normal lua search path.  if the library loaded has dependencies it will use the path in $LD_LIBRARY_PATH to search for them, or the rpath embedded in the library loaded.

On Thu, Sep 13, 2012 at 9:03 AM, Willi Schinmeyer <[hidden email]> wrote:
> Can I use require to load dynamic libraries?
Works on windows anyway. Not sure which directories are searched on
Linux, but it should work somehow.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Robert Vasek
On Thu, 13 Sep 2012, Tom McCubbin wrote:

> In linux it uses the normal lua search path.  if the library loaded has
> dependencies it will use the path in $LD_LIBRARY_PATH to search for them,
> or the rpath embedded in the library loaded.
>
> On Thu, Sep 13, 2012 at 9:03 AM, Willi Schinmeyer <[hidden email]>wrote:
>
> > > Can I use require to load dynamic libraries?
> > Works on windows anyway. Not sure which directories are searched on
> > Linux, but it should work somehow.
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>

Yeah when I type:
require("libhellobind.so")

apparently it can find the lib (which is located in the same dir as the
.lua file), however it gives me this error with an undefined symbol:
$ lua test.lua
lua: error loading module 'libhellobind.so' from file
'./libhellobind.so':
        ./libhellobind.so: undefined symbol:
_ZTIN7luabind6detail12registrationE
stack traceback:
        [C]: ?
        [C]: in function 'require'
        test.lua:6: in main chunk
        [C]: ?

So I may be creating the shared library somehow wrong.
$ g++ hellobind.cpp -I/usr/include/lua5.1/ -c -fPIC
$ g++ -shared -Wl,-soname,libhellobind.so.0 -o \
libhellobind.so.0.0 hellobind.o

test.lua:
    1 require("libhellobind.so")

And after running the lua file, the mentioned error occurs.

I've also found this:
http://www.gamedev.net/topic/624251-luabind-inside-a-shared-library/
"// int luaopen_[libname] is the entry point"
no luck with that either, still the same error.

Thanks for all the respones so far.

------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Trouble running the hello world application

Tom McCubbin-2
that is typeinfo for luabind::detail::registration which i'd bet is in the luabind library.

if you look at your link command below you will see you are not linking the luabind itself, hence the undefined symbol

add a -lluabind and all should be well.  you may need also to add a -L<where ever the lib is path> so the linker can find it.

-tom

ps - you don't need to add the .so when requiring the file, and you might drop the 'lib' prefix of the library to make it look more natural in lua.
then you could just right

require('hellobind')



On Fri, Sep 14, 2012 at 9:37 AM, Robert Vasek <[hidden email]> wrote:
On Thu, 13 Sep 2012, Tom McCubbin wrote:

> In linux it uses the normal lua search path.  if the library loaded has
> dependencies it will use the path in $LD_LIBRARY_PATH to search for them,
> or the rpath embedded in the library loaded.
>
> On Thu, Sep 13, 2012 at 9:03 AM, Willi Schinmeyer <[hidden email]>wrote:
>
> > > Can I use require to load dynamic libraries?
> > Works on windows anyway. Not sure which directories are searched on
> > Linux, but it should work somehow.
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > luabind-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>

Yeah when I type:
require("libhellobind.so")

apparently it can find the lib (which is located in the same dir as the
.lua file), however it gives me this error with an undefined symbol:
$ lua test.lua
lua: error loading module 'libhellobind.so' from file
'./libhellobind.so':
        ./libhellobind.so: undefined symbol:
_ZTIN7luabind6detail12registrationE
stack traceback:
        [C]: ?
        [C]: in function 'require'
        test.lua:6: in main chunk
        [C]: ?

So I may be creating the shared library somehow wrong.
$ g++ hellobind.cpp -I/usr/include/lua5.1/ -c -fPIC
$ g++ -shared -Wl,-soname,libhellobind.so.0 -o \
libhellobind.so.0.0 hellobind.o

test.lua:
    1 require("libhellobind.so")

And after running the lua file, the mentioned error occurs.

I've also found this:
http://www.gamedev.net/topic/624251-luabind-inside-a-shared-library/
"// int luaopen_[libname] is the entry point"
no luck with that either, still the same error.

Thanks for all the respones so far.

------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: *** GMX Spamverdacht *** Re: Trouble running the hello world application

Dennis Schridde
In reply to this post by Robert Vasek
Am Freitag, 14. September 2012, 15:37:26 schrieb Robert Vasek:
> So I may be creating the shared library somehow wrong.
> $ g++ hellobind.cpp -I/usr/include/lua5.1/ -c -fPIC
> $ g++ -shared -Wl,-soname,libhellobind.so.0 -o \
> libhellobind.so.0.0 hellobind.o
You need to link you SO with luabind, so the dynamic loader knows it has to
load that library in addition.

Add -lluabind to the end of the commandline.

--Dennis
------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: *** GMX Spamverdacht *** Re: Trouble running the hello world application

Robert Vasek
On Fri, 14 Sep 2012, Dennis Schridde wrote:

> Am Freitag, 14. September 2012, 15:37:26 schrieb Robert Vasek:
> > So I may be creating the shared library somehow wrong.
> > $ g++ hellobind.cpp -I/usr/include/lua5.1/ -c -fPIC
> > $ g++ -shared -Wl,-soname,libhellobind.so.0 -o \
> > libhellobind.so.0.0 hellobind.o
> You need to link you SO with luabind, so the dynamic loader knows it has to
> load that library in addition.
>
> Add -lluabind to the end of the commandline.
>
> --Dennis

omg I'm such a retard...I kept linking the luabind lib when calling g++
with -c option instead of linking it when creating the .so. It works
now! Thank you all, I really appreciate it.

------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user