首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使luabind在ubuntu工作?

如何使luabind在ubuntu工作?
EN

Stack Overflow用户
提问于 2016-12-18 09:24:38
回答 1查看 169关注 0票数 0

我一直在Ubuntu中尝试Luabind的你好,世界示例,但我无法让它工作。有人知道如何使用g++在Ubuntu中使用这个示例吗?

代码语言:javascript
复制
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ cat hellobind.cpp 
#include <iostream>
#include <luabind/luabind.hpp>

void greet()
{
    std::cout << "hello world!\n";
}

extern "C" int init(lua_State* L)
{
    using namespace luabind;

    open(L);

    module(L)
    [
        def("greet", &greet)
    ];

    return 0;
}
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ g++ hellobind.cpp -I/usr/include/lua5.2/ -c -fPIC
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ g++ -shared -Wl,--whole-archive -o hellobind.so hellobind.o -lluabind -Wl,--no-whole-archive
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ cat test.lua 
require 'hellobind'
greet()
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ lua test.lua 
lua: error loading module 'hellobind' from file './hellobind.so':
    ./hellobind.so: undefined symbol: luaopen_hellobind
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    test.lua:3: in main chunk
    [C]: in ?
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ 

当我运行lua脚本时,lua会抱怨“未定义的符号: luaopen_hellobind”。

我的系统详情如下:

代码语言:javascript
复制
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ dpkg --get-selections | grep -v deinstall | egrep 'lua|boost'
libboost-date-time1.54.0:amd64          install
libboost-dev                    install
libboost-system1.54.0:amd64         install
libboost1.54-dev                install
libboost1.55-tools-dev              install
liblua5.2-0:amd64               install
liblua5.2-dev:amd64             install
libluabind-dev                  install
libluabind-examples             install
libluabind0.9.1                 install
lua5.2                      install
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ gcc --version
gcc (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ uname -a
Linux castor-ub 3.19.0-43-generic #49~14.04.1-Ubuntu SMP Thu Dec 31 15:44:49 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
kuyu@castor-ub:~/dkuyu/Dropbox/practice/lua/luabind$ 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-18 09:38:07

我认为您正在查看这个示例这里,它们加载共享库的方式似乎不同。试试这样的lua脚本:

代码语言:javascript
复制
package.loadlib('hellobind.so', 'init')()
greet()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41207028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档