2016-12-18 4 views
0

나는 우분투에서 Luabind의 예를 hello world 시도했지만, 제대로 작동하지 못합니다. 누구든지이 예제를 g ++를 사용하여 우분투에서 작동시키는 방법을 알고 있습니까?우분투에서 루아 바인드가 어떻게 작동합니까?

[email protected]:~/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; 
} 
[email protected]:~/dkuyu/Dropbox/practice/lua/luabind$ g++ hellobind.cpp -I/usr/include/lua5.2/ -c -fPIC 
[email protected]:~/dkuyu/Dropbox/practice/lua/luabind$ g++ -shared -Wl,--whole-archive -o hellobind.so hellobind.o -lluabind -Wl,--no-whole-archive 
[email protected]:~/dkuyu/Dropbox/practice/lua/luabind$ cat test.lua 
require 'hellobind' 
greet() 
[email protected]:~/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 ? 
[email protected]:~/dkuyu/Dropbox/practice/lua/luabind$ 

내가 루아 스크립트를 실행하면, 루아는 불평 "정의되지 않은 심볼 : luaopen_hellobind을".

[email protected]:~/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 
[email protected]:~/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. 

[email protected]:~/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 
[email protected]:~/dkuyu/Dropbox/practice/lua/luabind$ 

답변

1

난 당신이 예를 here에서 찾고 생각하고, 그들이 다른 공유 라이브러리를로드하는 것 다음과 같이

내 시스템의 세부 정보입니다. 이 같은 루아 스크립트를 시도해보십시오

package.loadlib('hellobind.so', 'init')() 
greet() 
+0

Zekian을, 당신의 제안을 시도하고이 오류 얻을 : kuyu @ 캐스터-UB : ~/dkuyu/보관/연습/루아/luabind의 $ 고양이 test.lua 을인사말() 안녕하세요 : testluck : 4 : 전역 'loadlib'(nil 값)을 호출하려고 시도합니다. 스택 추적 : \t test.lua : 4 : 메인 덩어리 \t [C] : in? – kurt

+0

아, 새로운 버전의 lua에서는 package.loadlib 인 것 같습니다. –

+0

안녕 Zekian, 불행히도, 여전히 작동하지 않습니다. 그래도 도움을 주셔서 감사합니다. kuyu @ castor-ub : ~/dkuyu/Dropbox/연습/루아/루아빈드 $ cat test.lua package.loadlib ('hellobind.so', 'init') greet() kuyu @ castor- UB : ~/dkuyu/보관/연습/루아/luabind의 $ 루아 test.lua 루아 : test.lua : 1 : \t test.lua : 1 : 전무 값 스택 추적 호출 시도의 주요 청크를 \t [C] : in? – kurt