Last weekend I was trying to integrate LuaJIT into my custom game engine but I was getting this strange lua runtime error:
After a bit of googling I couldn't really find an answer, all the examples I found just worked. So I started to look a little deeper.
By looking at all of the final symbols from the binary I could see my test_ffi function was missing. From here I was fairly certain clang was stripping all of the dead code that wasn't being directly called. Which was causing my problem as I was using the FFI interface to export my C++ wrappers to lua. After a few more hours of googling I found a stackoverflow question about dead code striping that led me to adding this -Wl,-force_load,libstatic.a, to my linker command.
The symbol was now being correct "exported" from the static library to the host binary and not bring stripped. The output now worked correctly.
Below is all the source code used. You can also use -Wl,-all_load, which forces all symbols / functions to be imported even if unused. This will dramatically increase the size of the binary.
You can find all the source code on my github. Which includes a simple standalone single binary version, the above static library version and a dynamic library version. The code is written for OSX and a brew based install of LuaJIT. I didn't test if this was a issue on gcc or msvc++.