1. 程式人生 > 實用技巧 >[記錄點滴] 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