How to link luajit dynamic library file successfully?

  • From: Nan Xiao <xiaonan830818@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 28 Jul 2015 13:04:51 +0800

Hi all,

My OS in 64-bit Fedora Linux, after installing "luajit", the libraries are
installed in /usr/local/lib:

[root@Fedora lib]# pwd
/usr/local/lib
[root@Fedora lib]# ls -alt
total 2212
drwxr-xr-x. 2 root root 22 Jul 27 21:06 pkgconfig
drwxr-xr-x. 4 root root 4096 Jul 27 21:06 .
lrwxrwxrwx. 1 root root 22 Jul 27 21:06 libluajit-5.1.so ->
libluajit-5.1.so.2.0.4
lrwxrwxrwx. 1 root root 22 Jul 27 21:06 libluajit-5.1.so.2 ->
libluajit-5.1.so.2.0.4
-rwxr-xr-x. 1 root root 458144 Jul 27 21:06 libluajit-5.1.so.2.0.4
-rw-r--r--. 1 root root 790748 Jul 27 21:06 libluajit-5.1.a

I write a simple C program(a.c):

#include "luajit-2.0/lua.h"
#include "luajit-2.0/lualib.h"
#include "luajit-2.0/lauxlib.h"

int main(void) {
// Create new Lua state and load the lua libraries
lua_State *L = luaL_newstate();
luaL_openlibs(L);

// Tell Lua to load and run the file sample_script.lua
luaL_dostring(L, "print('Hello world!\n')");

// Close the Lua state
lua_close(L);
return 0;
}

Compile it:

gcc -g -o a a.c -lluajit-5.1

The compilation is success, but the ldd command shows that it can't find
luajit so file:

[root@Fedora test]# ldd a
linux-vdso.so.1 (0x00007ffe3576d000)
libluajit-5.1.so.2 => not found
libc.so.6 => /lib64/libc.so.6 (0x00007efc23278000)
/lib64/ld-linux-x86-64.so.2 (0x00007efc23638000)

How to link luajit dynamic library file successfully? Thanks very much in
advance!


Best Regards
Nan Xiao

Other related posts: