Hi Fran,
It appears you are linking the shared object to the executable. If you
do this, then the symbols are within the ffi.C. namespace, and you
should not need to ffi.load the shared object.
-Ryan
On Fri, Jun 12, 2015, at 11:20 PM, Francisco D' Agostino wrote:
> Guys, I'm using luajit as a shared library (libluajit.so) embedded in
> an C++ app. I've a shared library provided by a third party vendor
> (libctosapi.so) when trying to call a C function in this library from
> LUA using ffy I get 'undefined symbol'. Any kind of help is
> appreciated!
>
> *LUA Script (script.lua)*
>
> local ffi = require("ffi")
>
> ffi.cdef[[ unsigned short CTOS_PrinterPutString(unsigned char*
> baBuf); ]]
>
> local ctosapi = ffi.load("ctosapi")
>
> x = 0 for i = 1, #foo do x = x + foo[i]
> ctosapi.CTOS_PrinterPutString("Test") end
>
> return x
>
> *C++ Main* int main(int argc,char *argv[]) { BYTE key;
>
> CTOS_LCDTClearDisplay();
>
> int status, result, i; double sum; lua_State *L;
>
> L = luaL_newstate();
>
> luaL_openlibs(L); /* Load Lua libraries */
>
> status = luaL_loadfile(L, "script.lua"); if (status) { /* If
> something went wrong, error message is at the top of */ /* the
> stack */ fprintf(stderr, "Couldn't load file: %s\n",
> lua_tostring(L, -1)); exit(1); }
>
> lua_newtable(L); /* We will pass a table */
>
> for (i = 1; i <= 5; i++) { lua_pushnumber(L, i); /* Push
> the table index */ lua_pushnumber(L, i*2); /* Push the cell
> value */ lua_rawset(L, -3); /* Stores the pair in the
> table */ }
>
> lua_setglobal(L, "foo");
>
> result = lua_pcall(L, 0, LUA_MULTRET, 0); if (result) {
> fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -
> 1)); ABI_PrinterPutString((UCHAR *)lua_tostring(L, -1));
> exit(1); }
>
> sum = lua_tonumber(L, -1);
>
> if (sum == 30) ABI_PrinterPutString((UCHAR *)"SUCCESS!!!");
>
> lua_pop(L, 1); /* Take the returned value out of the stack */
> lua_close(L); /* Cya, Lua */
>
> CTOS_KBDGet(&key);
>
> exit(0); }
>
>
> *Compile/Linker Output*
>
> "/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS=
> .clean-conf make[1]: Entering directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5' rm -f -r build/Release rm -f
> dist/V5S/App/V8_TEST_VS5.exe make[1]: Leaving directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5'
>
>
> CLEAN SUCCESSFUL (total time: 670ms)
>
> "/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS=
> .build-conf make[1]: Entering directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5' "/usr/bin/make" -f nbproject/Makefile-
> Release.mk dist/V5S/App/V8_TEST_VS5.exe make[2]: Entering directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5' mkdir -p build/Release/Gnueabi-
> Windows arm-brcm-linux-gnueabi-g++ "-IC:\Program Files
> (x86)\Castles\VEGA5000S\include" -fsigned-char -Wundef -Wno-trigraphs
> -Wimplicit -Wformat -c -O2 -I/cygdrive/C/Program\ Files\
> \(x86\)/Castles/VEGA5000S/include -o build/Release/Gnueabi-
> Windows/appmain.o appmain.cpp mkdir -p dist/V5S/App arm-brcm-linux-gnueabi-
> g++ -L . "-LC:\Program Files (x86)\Castles\VEGA5000S\lib" "-
> LC:\Program Files (x86)\Castles\VEGA5000S\lib_not_builtin" -o
> dist/V5S/App/V8_TEST_VS5 build/Release/Gnueabi-Windows/appmain.o -
> lcaethernet -lcafont -lcafs -lcakms -lcalcd -lcamodem -lcapmodem -
> lcaprt -lcartc -lcauart -lcauldpm -lcausbh -lcagsm -lcabarcode -
> lpthread -ldl -lcaclvw -lcatls -lctosapi -lcrypto -lcurl -lssl -lz -
> lfreetype -lluajit make[2]: Leaving directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5' make[1]: Leaving directory
> `/cygdrive/c/dev/abidea/V8_TEST_VS5'
>
>
> BUILD SUCCESSFUL (total time: 2s)
>
> *Execution Output* script.lua:16: /usr/lib/libctosapi.so: undefined
> symbol : CTOS_PrinterPutString.
>
> Regards, Fran
>
> --
>
You received this message because you are subscribed to the Google
Groups "luvit" group.
>
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
>
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.