我有源文件
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 1024
int main() {
char line[BUFSIZE];
lua_State *L = lua_open();
while (fgets(line, sizeof(line), stdin) != 0) {
lua_dostring(L, line);
}
lua_close(L);
exit(0);
}
然后我运行gcc luac.c
,出错了。
Undefined symbols for architecture x86_64:
"_lua_close", referenced from:
_main in luac-9bbdf6.o
"_lua_dostring", referenced from:
_main in luac-9bbdf6.o
"_lua_open", referenced from:
_main in luac-9bbdf6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
好像我的lua.h
文件夹中没有/usr/local/include
。但它有。
ls -al /usr/local/include/lua.h
-rw-r--r--@ 1 root admin 11K Apr 3 16:23 /usr/local/include/lua.h
我有
ls -al /usr/local/lib/liblua.a
-rw-r--r-- 1 root admin 150448 Apr 3 16:23 /usr/local/lib/liblua.a
gcc搜索路径
gcc -Xlinker -v
(#)PROGRAM:ld PROJECT:ld64-305
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
...
为什么gcc说错误,你能告诉我吗。
问题是gcc默认不添加lua lib?
我使用gcc luac.c -llua -llualib
,有效。