lua-users home
lua-l archive

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

Thanks for the reply, Drake.  

When I tried adding -shared to the compile line, I got a strange error: 

matt@matt-BM412AA-ABA-CQ5600Y:~/Downloads/lua-5.2.0/src$ g++ dir.cpp -o -llua -shared
/usr/bin/ld: /usr/local/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/liblua.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

It says to recompile with fPIC (whatever that is?), but I tried that and still got the same exact error.

On Wed, Apr 24, 2013 at 9:07 PM, Drake Wilson <> wrote:
Quoth Matt Eisan <>, on 2013-04-24 20:42:40 -0400:
> I have attached the code I am using, and I compile with GCC using g++
> dir.cpp -o -llua
> int main() {
>       return 0;
> }

No, you want to create a shared library, not a main executable file.  Use g++
-shared and get rid of main(), to start with.  Nor, I think, will it work with
the name '' but an entrypoint function name of luaopen_mylib; the
expected load name should match the luaopen_* entrypoint and the .so basename,
as in loaded with require('foo') defining the C function luaopen_foo.

Also, all of the functions you're planning to cast to lua_CFunction (such as
l_dir), as well as the luaopen_* entrypoint, should be extern "C", if I'm not
mistaken.  (You'll also want to consider exceptions if you're interfacing to
C++, but that can be later.)

   ---> Drake Wilson