I just figured I can workaround that problem by using the LD_PRELOAD environment variable when invoking luajit, e.g.: `LD_PRELOAD=/path/to/libstdc++.so luajit main.lua'. I noticed lunar.so (my shared lib) doesn't appear to depend on libstdc++.so, so I guess this is why ffi.load / dlopen don't load it as a dependency: $ ldd lunar.so linux-vdso.so.1 => (0x00007fffb0a96000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f489b9ed000) /lib64/ld-linux-x86-64.so.2 (0x00007f489bfcd000) Does anyone know whether it's possible to make GCC specify libstdc++ as a dependency when building shared libraries? Atenciosamente / Sincerely, Guilherme Prá Vieira <http://www.linkedin.com/in/n2liquid> <http://www.linkedin.com/in/n2liquid> On Fri, Feb 27, 2015 at 2:01 AM, Guilherme Vieira < super.driver.512@xxxxxxxxx> wrote: > Hi, everyone. > > I'm trying out LuaJIT's FFI module. I'm not using a host program, but > importing a shared library using ffi.load instead, and running Lua code > using the `luajit' command. > > However I'm getting undefined symbol errors loading my shared lib, like > this one: > > $ luajit main.lua > luajit: main.lua:2: ./lunar.so: undefined symbol: _ZNSt8ios_base4InitD1Ev > stack traceback: > [C]: in function 'load' > main.lua:2: in main chunk > [C]: at 0x004049c0 > > More information: > > - LuaJIT version: 2.0.3. > - GCC version: 4.6.3 (used to compile both LuaJIT and my shared > library). > - Shared library GCC invocation: `gcc -shared -fPIC -Wall lunar.cpp -o > lunar.so'. > - Lua program invocation: `luajit main.lua'. > - main.lua / lunar.cpp sources and invocation strace: > gist.github.com/n2liquid/a71d086d38afae3dd6dc. > > I really couldn't find information about this searching the web (still a > newb, so I probably don't know how to search properly). Most Q&As revolved > around using a C host program, but like I said, that's not my case. > > If I simply remove `#include <iostream>' from lunar.cpp, it works just > fine. > > Can someone please help? > > Atenciosamente / Sincerely, > Guilherme Prá Vieira > > <http://www.linkedin.com/in/n2liquid> > <http://www.linkedin.com/in/n2liquid> >