Luaopen_my_example undefined after swig wrapper compilation

I am now diving into SWIG as a means to create Lua bindings and I fell into a trap. I made my interface file and created a generic object file from it with no problem. However, when I start Lua and try to claim a shared object, I get this:

Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
 require ("my_example")
 error loading module 'my_example' from file './my_example.so':

        ./my_example.so: undefined symbol: luaopen_my_example

stack trace:

[C]:?

[C]: in function 'require'

stdin: 1: in main chunk

[C]:?

I can't seem to find anything online describing this situation, so I thought I'd post here. Is there a SWIG guru out there? The class I am wrapping is several thousand lines long (and proprietary), or I would post it here.

Thank you !: D

+1


a source to share


2 answers


Which version of SWIG are you using and on which platform?

The slightly outdated version 1.3.29 of SWIG that I ran under Cygwin uses #define SWIG_init

deep in its generated wrapper file to specify the name it wanted require

as luaopen_mod

where mod

was the name used in the statement %module

at the top of the SWIG file .i

. The module I wrapped loads and works with Lua 5.1 on Windows.



You may also need to do something to make sure that this symbol is exported and not called a C ++ name that Lua will never find. I was wrapping C structures and part of the Windows API, so I didn't deal with any specific C ++ issues in that wrapper. However, accidental manipulation of names is often the cause of module loading problems even without SWIG involvement.

+1


a source


/ Facepalm



I had the wrong module code in the interface file (.i). Thanks anyway!

+1


a source







All Articles