21 #include <string.h>
22 #include <math.h>
23
24 #include <lua.h>
25 #include <lauxlib.h>
26 #include <lualib.h>
27
28 int main(void)
29 {
30 char buff[256];
31 int error;
32 lua_State *L = lua_open();
33 luaopen_base(L);
34 luaopen_table(L);
35 luaopen_io(L);
36 luaopen_string(L);
37 luaopen_math(L);
38
39 while (fgets(buff, sizeof(buff), stdin) != NULL)
40 {
41 error = luaL_loadbuffer(L, buff, strlen(buff), "line")
42 || lua_pcall(L, 0, 0, 0);
43
44 if (error)
45 {
46 fprintf(stderr, "%s", lua_tostring(L, -1));
47 lua_pop(L, 1);
48 }
49 }
50
51 lua_close(L);
52
53 return 0;
54 }
就是上面的代码,如何用gcc 或者是g++编译啊,该如何指定参数,谢谢各位!
4 个解决方案
#1
` pkg-config --cflags --libs lua5.1`
或
-I/usr/include/lua5.1 -llua5.1
版本不同或有差異.
gcc -I /usr/include/lua5.1/ -o aa aa.c -llua5.1
或
-I/usr/include/lua5.1 -llua5.1
版本不同或有差異.
gcc -I /usr/include/lua5.1/ -o aa aa.c -llua5.1
#2
gangjh,我刚刚试过了,不行啊!我得lua是5.1的。
#3
bash-3.1-$ gcc -o test test.c -llua -ldl
我这样编译时出现如下的错误,该怎么办呢?请各位给予指点!
/usr/local/lib/liblua.a(lvm.o): In function `Arith':
lvm.c:(.text+0xbf9): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x1ffe): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tan':
lmathlib.c:(.text+0x1ee): undefined reference to `tan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tanh':
lmathlib.c:(.text+0x22e): undefined reference to `tanh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sqrt':
lmathlib.c:(.text+0x27d): undefined reference to `sqrt'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sin':
lmathlib.c:(.text+0x2be): undefined reference to `sin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sinh':
lmathlib.c:(.text+0x2fe): undefined reference to `sinh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_pow':
lmathlib.c:(.text+0x488): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log':
lmathlib.c:(.text+0x52e): undefined reference to `log'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log10':
lmathlib.c:(.text+0x56e): undefined reference to `log10'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_fmod':
lmathlib.c:(.text+0x678): undefined reference to `fmod'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_exp':
lmathlib.c:(.text+0x6be): undefined reference to `exp'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cos':
lmathlib.c:(.text+0x6fe): undefined reference to `cos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cosh':
lmathlib.c:(.text+0x73e): undefined reference to `cosh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan':
lmathlib.c:(.text+0x77e): undefined reference to `atan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan2':
lmathlib.c:(.text+0x7d8): undefined reference to `atan2'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_asin':
lmathlib.c:(.text+0x81e): undefined reference to `asin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_acos':
lmathlib.c:(.text+0x85e): undefined reference to `acos'
/usr/local/lib/liblua.a(lcode.o): In function `codearith':
lcode.c:(.text+0x11ea): undefined reference to `pow'
collect2: ld returned 1 exit status
我这样编译时出现如下的错误,该怎么办呢?请各位给予指点!
/usr/local/lib/liblua.a(lvm.o): In function `Arith':
lvm.c:(.text+0xbf9): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x1ffe): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tan':
lmathlib.c:(.text+0x1ee): undefined reference to `tan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tanh':
lmathlib.c:(.text+0x22e): undefined reference to `tanh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sqrt':
lmathlib.c:(.text+0x27d): undefined reference to `sqrt'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sin':
lmathlib.c:(.text+0x2be): undefined reference to `sin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sinh':
lmathlib.c:(.text+0x2fe): undefined reference to `sinh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_pow':
lmathlib.c:(.text+0x488): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log':
lmathlib.c:(.text+0x52e): undefined reference to `log'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log10':
lmathlib.c:(.text+0x56e): undefined reference to `log10'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_fmod':
lmathlib.c:(.text+0x678): undefined reference to `fmod'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_exp':
lmathlib.c:(.text+0x6be): undefined reference to `exp'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cos':
lmathlib.c:(.text+0x6fe): undefined reference to `cos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cosh':
lmathlib.c:(.text+0x73e): undefined reference to `cosh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan':
lmathlib.c:(.text+0x77e): undefined reference to `atan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan2':
lmathlib.c:(.text+0x7d8): undefined reference to `atan2'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_asin':
lmathlib.c:(.text+0x81e): undefined reference to `asin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_acos':
lmathlib.c:(.text+0x85e): undefined reference to `acos'
/usr/local/lib/liblua.a(lcode.o): In function `codearith':
lcode.c:(.text+0x11ea): undefined reference to `pow'
collect2: ld returned 1 exit status
#4
gcc -o test test.c -llua -ldl -lm
你掉了数学库
你掉了数学库
#1
` pkg-config --cflags --libs lua5.1`
或
-I/usr/include/lua5.1 -llua5.1
版本不同或有差異.
gcc -I /usr/include/lua5.1/ -o aa aa.c -llua5.1
或
-I/usr/include/lua5.1 -llua5.1
版本不同或有差異.
gcc -I /usr/include/lua5.1/ -o aa aa.c -llua5.1
#2
gangjh,我刚刚试过了,不行啊!我得lua是5.1的。
#3
bash-3.1-$ gcc -o test test.c -llua -ldl
我这样编译时出现如下的错误,该怎么办呢?请各位给予指点!
/usr/local/lib/liblua.a(lvm.o): In function `Arith':
lvm.c:(.text+0xbf9): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x1ffe): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tan':
lmathlib.c:(.text+0x1ee): undefined reference to `tan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tanh':
lmathlib.c:(.text+0x22e): undefined reference to `tanh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sqrt':
lmathlib.c:(.text+0x27d): undefined reference to `sqrt'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sin':
lmathlib.c:(.text+0x2be): undefined reference to `sin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sinh':
lmathlib.c:(.text+0x2fe): undefined reference to `sinh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_pow':
lmathlib.c:(.text+0x488): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log':
lmathlib.c:(.text+0x52e): undefined reference to `log'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log10':
lmathlib.c:(.text+0x56e): undefined reference to `log10'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_fmod':
lmathlib.c:(.text+0x678): undefined reference to `fmod'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_exp':
lmathlib.c:(.text+0x6be): undefined reference to `exp'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cos':
lmathlib.c:(.text+0x6fe): undefined reference to `cos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cosh':
lmathlib.c:(.text+0x73e): undefined reference to `cosh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan':
lmathlib.c:(.text+0x77e): undefined reference to `atan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan2':
lmathlib.c:(.text+0x7d8): undefined reference to `atan2'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_asin':
lmathlib.c:(.text+0x81e): undefined reference to `asin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_acos':
lmathlib.c:(.text+0x85e): undefined reference to `acos'
/usr/local/lib/liblua.a(lcode.o): In function `codearith':
lcode.c:(.text+0x11ea): undefined reference to `pow'
collect2: ld returned 1 exit status
我这样编译时出现如下的错误,该怎么办呢?请各位给予指点!
/usr/local/lib/liblua.a(lvm.o): In function `Arith':
lvm.c:(.text+0xbf9): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x1ffe): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tan':
lmathlib.c:(.text+0x1ee): undefined reference to `tan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_tanh':
lmathlib.c:(.text+0x22e): undefined reference to `tanh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sqrt':
lmathlib.c:(.text+0x27d): undefined reference to `sqrt'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sin':
lmathlib.c:(.text+0x2be): undefined reference to `sin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_sinh':
lmathlib.c:(.text+0x2fe): undefined reference to `sinh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_pow':
lmathlib.c:(.text+0x488): undefined reference to `pow'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log':
lmathlib.c:(.text+0x52e): undefined reference to `log'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_log10':
lmathlib.c:(.text+0x56e): undefined reference to `log10'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_fmod':
lmathlib.c:(.text+0x678): undefined reference to `fmod'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_exp':
lmathlib.c:(.text+0x6be): undefined reference to `exp'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cos':
lmathlib.c:(.text+0x6fe): undefined reference to `cos'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_cosh':
lmathlib.c:(.text+0x73e): undefined reference to `cosh'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan':
lmathlib.c:(.text+0x77e): undefined reference to `atan'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_atan2':
lmathlib.c:(.text+0x7d8): undefined reference to `atan2'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_asin':
lmathlib.c:(.text+0x81e): undefined reference to `asin'
/usr/local/lib/liblua.a(lmathlib.o): In function `math_acos':
lmathlib.c:(.text+0x85e): undefined reference to `acos'
/usr/local/lib/liblua.a(lcode.o): In function `codearith':
lcode.c:(.text+0x11ea): undefined reference to `pow'
collect2: ld returned 1 exit status
#4
gcc -o test test.c -llua -ldl -lm
你掉了数学库
你掉了数学库