After reading up lots of gcc docomentation and similar questions my problem remains.
Im trying to statically link my libluajit.a into my project but no matter what combination of commands I try, one or another error pops up. Ive successfully compiled my project with dynamic linking though.
Right now Im out of ideas so heres what i got right now:
gcc_options = -std=c++11 -static -pthread
src_dir = LuaHost
src_files = $(src_dir)/*.cpp
src_files += $(src_dir)/*.h
src_files += $(src_dir)/LuaSrc/*.h
src_files += $(src_dir)/LuaSrc/*.hpp
lib_cmd = -Wl,--no-as-needed -ldl -L./$(src_dir)/LuaSrc/ -lluajit
#compile everything and output an executeable
all:
g++ $(gcc_options) $(src_files) $(lib_cmd) -o LuaJITSandbox.o
And heres some of the errors:
./LuaHost/LuaSrc/libluajit.a(lj_clib.o): In function `lj_clib_index':
lj_clib.c:(.text+0x1c0): undefined reference to `dlsym'
./LuaHost/LuaSrc/libluajit.a(lj_clib.o): In function `lj_clib_load':
lj_clib.c:(.text+0x2c8): undefined reference to `dlopen'
lj_clib.c:(.text+0x350): undefined reference to `dlerror'
lj_clib.c:(.text+0x424): undefined reference to `dlopen'
The libluajit.a has been compiled on the same machine, a RaspberryPi.
I think
-staticis not what you are after.-staticwill build astatic applicationand does not meanlink this static library to the application.There are a few options here. When you link with
-lluajityou could remove the the dynamic.soversion of the library. gcc will default to dynamic linking, but will fallback to static linking when the dynamic library is not available or not found.Instead of
-lluajityou could just point to the static library file directly - treating it as an object input file:/usr/lib/libluajit.a.I think the recommend way is to tell the linker how to link you library. Try using
-Wl,-Bstatic -lluajit. You can switch betweenBstaticandBdynamicright in front of the library name in case you link to multiple libraries and want to link them differently.