其他分享
首页 > 其他分享> > [记录点滴] luaxml编译过程

[记录点滴] luaxml编译过程

作者:互联网

[记录点滴] luaxml编译

记录一次luaxml编译的解决过程
参考 http://blog.csdn.net/dc_show/article/details/38957991

0x01 编译错误

编译错误 1

make
gcc -Os -Wall -c  -fPIC -I../lua/src -c LuaXML_lib.c
LuaXML_lib.c:36:17: 致命错误:lua.h:没有那个文件或目录
 #include <lua.h>
                 ^
编译中断。
make: *** [LuaXML_lib.o] 错误 1

服务器上lua的状态

[root@iZ255h7jx9sZ luaxml-master]# which lua
/usr/bin/lua
[root@iZ255h7jx9sZ luaxml-master]# lua -v
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio

需要修改其中的Makefile文件,将头文件和库文件的目录换成系统中lua头文件和库文件所在的目录。

查找头文件 find / -name "lua.h" ,显示在
/usr/local/openresty/luajit/include/luajit-2.1/lua.h

查找库文件 find / -name "liblua*.a",显示在
/usr/local/openresty/luajit/lib/libluajit-5.1.a

编译错误 2

make,这里可能会提示找不到llua
也需要修改Makefile

[root@iZ255h7jx9sZ luaxml-master]# make
gcc -Os -Wall -c  -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1/ -c LuaXML_lib.c
gcc -o LuaXML_lib.so -fPIC -shared LuaXML_lib.o -L. -L../usr/local/openresty/luajit/lib/  -llua -ldl 
/usr/bin/ld: cannot find -llua
collect2: 错误:ld 返回 1
make: *** [LuaXML_lib.so] 错误 1

在服务器上继续找,找到了
/usr/lib64/liblua-5.1.so

0x02 最终 Makefile

文件如下

# 2009-03-16 by gf

# generic compiler and linker settings:
CC     = gcc
INCDIR = -I/usr/local/openresty/luajit/include/luajit-2.1/
LIB    = 
LIBDIR =  -L. -L/usr/lib64/
CFLAGS = -Os -Wall -c #-g

# generic platform specific rules:
ARCH            = $(shell uname -s)
ifeq ($(ARCH),Linux)
  CFLAGS += -fPIC
  LFLAGS =  -fPIC -shared
  LIBS          = $(LIBDIR) $(LIB) -llua-5.1 -ldl
  EXESUFFIX =
  SHLIBSUFFIX = .so

else  
  ifeq ($(ARCH),Darwin) # MacOSX
    LFLAGS = -bundle 
    LIBS          = $(LIBDIR) -L/usr/local/lib $(LIB) -llua
    EXESUFFIX = .app
    SHLIBSUFFIX = .so
    
  else  # windows, MinGW
    LFLAGS =  -shared
    LIBS          = $(LIBDIR) $(LIB) -llua51 -mconsole -s
    EXESUFFIX = .exe
    SHLIBSUFFIX = .dll

  endif
endif

# project specific targets:
all:  LuaXML_lib$(SHLIBSUFFIX)

# project specific link rules:
LuaXML_lib$(SHLIBSUFFIX): LuaXML_lib.o
  $(CC) -o $@ $(LFLAGS) $^ $(LIBS) 

# project specific dependencies:
LuaXML_lib.o:  LuaXML_lib.c

# generic rules and targets:
.c.o:
  $(CC) $(CFLAGS) $(INCDIR) -c $<
clean:
  rm -f *.o *~ LuaXML_lib.so LuaXML_lib.dll

标签:luajit,lib,lua,编译,usr,luaxml,local,点滴,LuaXML
来源: https://www.cnblogs.com/rossiXYZ/p/13196503.html