1. Install LUA first
Linux system
Make Linux
Make install
2, compile
GCC-LM-G-O test TEST.C/USR/LOCAL/LIB/LIBLUA.A-LDL
If less-LDL, then the compilation will be reported:
GCC-LM-G-O test test.c/usr/local/lib/liblua.a
/USR/LOCAL/LIB/LIBLUA.A (LOADLIB.O): in function ' GCTM ':
LOADLIB.C: (. text+0x35): Undefined reference to ' dlclose '
/USR/LOCAL/LIB/LIBLUA.A (LOADLIB.O): in function ' Ll_loadfunc ':
LOADLIB.C: (. text+0xc0): Undefined reference to ' Dlopen '
LOADLIB.C: (. text+0xfc): Undefined reference to ' Dlsym '
LOADLIB.C: (. text+0x198): Undefined reference to ' dlerror '
LOADLIB.C: (. text+0x1bb): Undefined reference to ' dlerror '
If you are less liblua.a, you will report the following questions:
[Wangbin@tuan lua]$ gcc-lm-g-o test TEST.C-LDL
/tmp/ccct0d24.o:in function ' main ':
/home/wangbin/work/tmp/lua/test.c:26:undefined reference to ' lual_newstate '
/home/wangbin/work/tmp/lua/test.c:27:undefined reference to ' Lual_openlibs '
/home/wangbin/work/tmp/lua/test.c:29:undefined reference to ' Lual_loadbufferx '
/home/wangbin/work/tmp/lua/test.c:29:undefined reference to ' Lua_pcallk '
/home/wangbin/work/tmp/lua/test.c:32:undefined reference to ' lua_tolstring '
/home/wangbin/work/tmp/lua/test.c:33:undefined reference to ' Lua_settop '
/home/wangbin/work/tmp/lua/test.c:36:undefined reference to ' Lua_close '
Collect2:ld returned 1 exit status
If less-lm, the results are as follows:
[Wangbin@tuan lua]$ gcc-g-o test TEST.C/USR/LOCAL/LIB/LIBLUA.A-LDL
/USR/LOCAL/LIB/LIBLUA.A (LOBJECT.O): in function ' Luao_arith ':
LOBJECT.C: (. text+0xdf): Undefined reference to ' POW '
/USR/LOCAL/LIB/LIBLUA.A (LVM.O): in function ' Luav_execute ':
LVM.C: (. text+0x159a): Undefined reference to ' POW '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_sin ':
LMATHLIB.C: (. text+0x3e): Undefined reference to ' sin '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_sinh ':
LMATHLIB.C: (. text+0x6e): Undefined reference to ' Sinh '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_cos ':
LMATHLIB.C: (. text+0x9e): Undefined reference to ' cos '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_cosh ':
LMATHLIB.C: (. text+0xce): Undefined reference to ' cosh '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_tan ':
LMATHLIB.C: (. Text+0xfe): Undefined reference to ' tan '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_tanh ':
LMATHLIB.C: (. text+0x12e): Undefined reference to ' Tanh '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_asin ':
LMATHLIB.C: (. text+0x15e): Undefined reference to ' ASIN '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_acos ':
LMATHLIB.C: (. text+0x18e): Undefined reference to ' ACOs '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_atan ':
LMATHLIB.C: (. text+0x1be): Undefined reference to ' Atan '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' math_atan2 ':
LMATHLIB.C: (. text+0x1fb): Undefined reference to ' atan2 '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_fmod ':
LMATHLIB.C: (. text+0x2db): Undefined reference to ' fmod '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' math_sqrt ':
LMATHLIB.C: (. text+0x391): Undefined reference to ' sqrt '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_pow ':
LMATHLIB.C: (. text+0x3d3): Undefined reference to ' POW '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_log ':
LMATHLIB.C: (. text+0x450): Undefined reference to ' log '
LMATHLIB.C: (. text+0x460): Undefined reference to ' log '
LMATHLIB.C: (. text+0x486): Undefined reference to ' log10 '
LMATHLIB.C: (. text+0x4aa): Undefined reference to ' log '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' MATH_LOG10 ':
LMATHLIB.C: (. text+0x4de): Undefined reference to ' log10 '
/USR/LOCAL/LIB/LIBLUA.A (LMATHLIB.O): in function ' Math_exp ':
LMATHLIB.C: (. text+0x50e): Undefined reference to ' exp '
Collect2:ld returned 1 exit status