lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 29/01/2015, at 10:15 pm, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 
> I'm for the first time ever trying to make a Lua binding to a package
> written in C++, not C. I put my .cc file inside the source library of that
> package and compile with this in my Makefile (Ubuntu 14.04):
> 
> OFILES = [list of .o files to be compiled for the package]
> 
> CPPFLAGS = -fPIC
> 
> mybinding.so: mybinding.o $(OFILES)
>    cc -shared -fPIC $(OFILES) mybinding.o -o mybinding.so
> 
> The default rule for making an object file comes out as e.g.
> 
> g++  -fPIC  -c -o mybinding.o mybinding.cc
> 
> When I run this, I get:
> $ lua -l mybinding
> lua: error loading module 'mybinding' from file './mybinding.so':
>    ./mybinding.so: undefined symbol: _Z15lua_createtableP9lua_Stateii
> 
> This is clearly some C++ mangling of a call to lua_createtable.
> I suspect I should make a special Lua executable using g++ as
> compiler instead of cc, but this is the point at which I decide to ask
> the experts first!

You could try wrapping an ‘extern “C” { … }’ around your #include “lua….h”s.  That might help?