2017-10-26 11 views
1

いくつかの機能のためにいくつかのluaスクリプトを呼び出すC++(レガシー)アプリケーションがあります。luaは私のC++共有ライブラリを読み込みますが、依存する共有ライブラリは読み込みません。

私はそのluaスクリプトから呼び出されるべき新しいC++ライブラリを書いています。

#include <lua.hpp> 

extern "C" { 

static int isquare(lua_State *L){    /* Internal name of func */ 
     return 1;        /* One return value */ 
} 
static int icube(lua_State *L){    /* Internal name of func */ 
     return 1;        /* One return value */ 
} 


/* Register this file's functions with the 
* luaopen_libraryname() function, where libraryname 
* is the name of the compiled .so output. In other words 
* it's the filename (but not extension) after the -o 
* in the cc command. 
* 
* So for instance, if your cc command has -o power.so then 
* this function would be called luaopen_power(). 
* 
* This function should contain lua_register() commands for 
* each function you want available from Lua. 
* 
*/ 
int luaopen_power(lua_State *L){ 
     printf("before power open"); 
     lua_register(
         L,    /* Lua state variable */ 
         "square",  /* func name as known in Lua */ 
         isquare   /* func name in this file */ 
         ); 

     lua_register(L,"cube",icube); 
     printf("after power register"); 
     return 0; 
} 
} 

g++ -Wall -shared -fPIC -o power.so -I/usr/include/lua5.1 hellofunc.cpp -lstdc++ 

リンクのためのファイルはありませんでした。

しかし、このpower.soは実行時にlua-5.1.soが必要です。

今、私はlua52がコンパイルされたC++レガシーアプリケーションを持っています。

そして、それはalert.luaを呼び出しています。

package.cpath = package.cpath .. ";/usr/lib64/power.so" 
package.cpath = package.cpath .. ";/usr/lib64/liblua-5.1.so" 
require("power") 

注:power.soをロードLUAはPower.soがコンパイルされ

lua5.2上で動作し、lua5.1

に依存し、私はエラーに取得

undefined symbol: lua_setfield' 

これらのバージョンは同じである必要がありますか?

誰かがこの問題を明らかにすることはできますか?

EDIT:lua52.soでpower.soをコンパイルすると、luaスクリプトとC++アプリケーションが異常に異常終了します。

power.soをビルドしているときに-llua52と指定しないと、実行時に未定義のシンボルが表示されるというエラーがあります。

EDIT:詳細説明:

C++アプリケーション.exeがあります。 (samplecpp) lua 5.2ライブラリと一緒にビルドされた.dll/.shもあります。したがって、luaと他の機能を備えています。 (luaplugin.so)

このluaplugin.soは、設定されている任意のluaスクリプトを呼び出すことができます。 luaスクリプトで関数を呼び出して実行します。

私は別のC + +モジュールにつなげたいと思うluaスクリプトがあります。

(ビルドする.soはlua52.soに依存しています)私は順番に、登録などのためにlua関数を使用しています。これはluaスクリプトからロードする必要があるためです。

実行時にsamplecppがluaスクリプトを実行し、luascriptにC++ .soが必要な場合は、C++ .soで使用されるlua関数で未解決のエラーが表示されます。

私はそれがsamplecpp自体で利用できるlua関数を参照するようにすることはできますか?

答えて

0

はい、同じバージョンのLua用にコンパイルされたC/C++ライブラリを使用する必要があります。

Luaの異なるバージョン間でABI互換性はありません。
http://www.lua.org/versions.html#numbering

関連する問題