Compiling Lua Lib in VC/compiling Lua library with bcb6

Source: Internet
Author: User
Tags gz file

Lua provides source code for compilation by users. You can compile it into a static library or a dynamic library. However, Lua does not provide engineering files and needs to be added by the user. This is inconvenient for new users.
I. Lua static library
Compiling to a static library is simple. Someone has already written it. The following is an excerpt:
Lua includes core lib and standard lib. For details, refer to the document. For simplicity, we put it in a lib. We need to create a static library project, add the source file to the project, including the following files
Core lib: lapi. c lcode. c ldebug. c. c ldump. c lfunc. c lgc. c llex. c lmem. c lobject. c lopcodes. c lp *** r. c lstate. c lstring. c ltable. c ltests. c ltm. c lundump. c lvm. c lzio. c
Standard lib: lauxlib. c lbaselib. c ldblib. c liolib. c lmathlib. c ltablib. c
Lstrlib. c loadlib. c
And set the output path to lib.
Ii. Lua dynamic library
To compile a dynamic library, first modify the Lua. h header file. As follows:
/* Mark for all API functions */
// # Ifndef LUA_API
// # Define LUA_API extern
// # Endif
# Ifdef LUA502_EXPORTS // depends on your project
# Define LUA_API _ declspec (dllexport)
# Else
# Define LUA_API _ declspec (dllimport)
# Endif
Then, use vc to create a win32 dll, which contains the *. h and *. c files (refer to 1). compile it.
3. About LuaBind
LuaBind is a package for Lua to facilitate interaction with C ++. Similarly, LuaBind only provides source code. Use it in VC without compiling it into a dynamic library or dll. You only need to include the *. cpp file of LuaBind in the project. LuaBind6 uses Boost 1.30.0, so you need to perform the following operations (Boost in a later version is not supported ).
In addition, LuaBind may cause various problems in VC6 sp5, so it is better to use a later version of VC.

Bytes ------------------------------------------------------------------------------------------

Lua is a completely free scripting language, which can be used independently or embedded in the C/C ++ language as an embedded script.
You can go to its official website http://www.lua.org to download the latest lua source code, this makefile is for the lua-5.1.3.

Download is a tar.gz file. After decompression, no compilation method for BCB is found. Later, I found a solution for the "birds of prey" master on the Internet: http://mental.we8log.com/entry/89. I wrote this makefile by referring to the "birds of prey" big solution.

Copy the following text and save it as makefile. bcc, and store it in the lua/src subdirectory.

In the command line mode, enter the lua/src directory and enter the command:
Make-f makefile. bcc
You can generate lua_bc.dll,lua_bc.lib,lua_bc.exe.luac_bc.exe.

To generate a static library, enter the following command:
Make-f makefile. bcc-DSTATIC
Liblua_bc.lib,lua_bc.exe.luac_bc.exe can be generated.

The contents of makefile. bcc are as follows:

# Makefile for Borland C ++ 5.5

# Usage:
# Build lua with dll: make-f makefile. bcc
# Build lua with static library: make-f makefile. bcc-DSTATIC

# Write by: Mao yongjun (mao_yj@msn.com)

# Makefile for building Lua
# See ../INSTALL for installation instructions
# See ../Makefile and luaconf. h for further customization

#== Change the settings below to suit your environment =========================

CC = bcc32
CFLAGS =-DNDEBUG-DNO_STRICT; _ NO_VCL-Hc-w-par-O2-B-k--vi-tWM-c-P-
CFLAGSEXE =-D_isatty = isatty $ (CFLAGS)
CLINK = ilink32
CLFLAGS =-Gn-j-x
DLLOBJS = c0d32. obj
EXEOBJS = c0x32. obj
STDLIBS = import32.lib cw32mt. lib
LIB = tlib
RM = del/F

#== End of user settings. no need to change anything below this line ==========

LUA_D = lua_bc.dll
LUA_DA = $ (LUA_D:. dll =. lib)
LUA_SA = liblua_bc.lib

! Ifdef STATIC
LUA_A = $ (LUA_SA)
! Else
LUA_A = $ (LUA_DA)
CFLAGS =-DLUA_BUILD_AS_DLL $ (CFLAGS)
CFLAGSEXE =-DLUA_BUILD_AS_DLL $ (CFLAGSEXE)
! Endif

CORE_O = lapi. obj lcode. obj ldebug. obj drop. obj ldump. obj lfunc. obj lgc. obj llex. obj lmem. obj/
Lobject. obj lopcodes. obj lparser. obj lstate. obj lstring. obj ltable. obj ltm. obj/
Lundump. obj lvm. obj lzio. obj
LIB_O = lauxlib. obj lbaselib. obj ldblib. obj liolib. obj lmathlib. obj loslib. obj ltablib. obj/
Lstrlib. obj loadlib. obj linit. obj
LINK_O = $ (CORE_O) $ (LIB_O)

PLINK_O = + lapi. obj + lcode. obj + ldebug. obj + ldump. obj + lfunc. obj + lgc. obj + llex. obj + lmem. obj/
+ Lobject. obj + lopcodes. obj + lparser. obj + lstate. obj + lstring. obj + ltable. obj + ltm. obj/
+ Lundump. obj + lvm. obj + lzio. obj/
+ Lauxlib. obj + lbaselib. obj + ldblib. obj + liolib. obj + lmathlib. obj + loslib. obj + ltablib. obj/
+ Lstrlib. obj + loadlib. obj + linit. obj

LUA_T = lua_bc.exe
LUA_O = lua. obj

LUAC_T = luac_bc.exe
LUAC_O = luac. obj print. obj $ (CORE_O)

ALL_O = $ (CORE_O) $ (LIB_O) $ (LUA_O) $ (LUAC_O)
ALL_A = $ (LUA_A)
ALL_T = $ (ALL_A) $ (LUA_T) $ (LUAC_T)

All: $ (ALL_T)
$ (RM) $ (ALL_O) *. tds
O: $ (ALL_O)

A: $ (ALL_A)

$ (LUA_DA): $ (LUA_D)

$ (LUA_SA): $ (LINK_O)
$ (LIB) $ @ $ (PLINK_O)

$ (LUA_D): $ (LINK_O)
$ (CLINK) $ (CLFLAGS)-Tpd-Gi $ (DLLOBJS) $ (LINK_O), $ @, $ (STDLIBS ),,

$ (LUA_T): $ (LUA_O) $ (LUA_A)
$ (CLINK) $ (CLFLAGS)-Tpe $ (EXEOBJS) $ (LUA_O), $ @, $ (STDLIBS) $ (LUA_A ),,

$ (LUAC_T): $ (LUAC_O) $ (LUA_A)
$ (CLINK) $ (CLFLAGS)-Tpe $ (EXEOBJS) $ (LUAC_O), $ @, $ (STDLIBS) $ (LUA_A ),,

Clean:
$ (RM) $ (ALL_T) $ (ALL_O) $ (LUA_D) *. tds

. PHONY: clean all o

# DO NOT DELETE
Lapi. obj: lapi. c lua. h luaconf. h lapi. h lobject. h llimits. h ldebug. h/
Lstate. h ltm. h lzio. h lmem. h lmem. h lfunc. h lgc. h lstring. h ltable. h/
Lundump. h lvm. h
$ (CC) $ (CFLAGS) lapi. c
Lauxlib. obj: lauxlib. c lua. h luaconf. h lauxlib. h
$ (CC) $ (CFLAGS) lauxlib. c
Lbaselib. obj: lbaselib. c lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (CFLAGS) lbaselib. c
Lcode. obj: lcode. c lua. h luaconf. h lcode. h llex. h lobject. h llimits. h/
Lzio. h lmem. h lopcodes. h lparser. h ldebug. h lstate. h ltm. h drop-down. h lgc. h/
Ltable. h
$ (CC) $ (cflags) lcode. c
Ldblib. OBJ: ldblib. c Lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (cflags) ldblib. c
Ldebug. OBJ: ldebug. c Lua. h luaconf. h lapi. h lobject. h llimits. h lcode. h/
Llex. h lzio. h lmem. h lopcodes. h lparser. h ldebug. h lstate. h ltm. h drop. h/
Lfunc. h lstring. h lgc. h ltable. h LVM. h
$ (CC) $ (cflags) ldebug. c
*. OBJ/
Lzio. h lmem. h LDC. h lfunc. h lgc. h lopcodes. h lparser. h lstring. h/
Ltable. h lundump. h LVM. h
$ (CC) $ (cflags) LDC. c
Ldump. obj: ldump. c lua. h luaconf. h lobject. h llimits. h lstate. h ltm. h/
Lzio. h lmem. h lundump. h
$ (CC) $ (CFLAGS) ldump. c
Lfunc. obj: lfunc. c lua. h luaconf. h lfunc. h lobject. h llimits. h lgc. h lmem. h/
Lstate. h ltm. h lzio. h
$ (CC) $ (CFLAGS) lfunc. c
Lgc. obj: lgc. c lua. h luaconf. h ldebug. h lstate. h lobject. h llimits. h ltm. h/
Lzio. h lmem. h LDC. h lfunc. h lgc. h lstring. h ltable. h
$ (CC) $ (CFLAGS) lgc. c
Linit. obj: linit. c lua. h luaconf. h lualib. h lauxlib. h
$ (CC) $ (CFLAGS) linit. c
Liolib. obj: liolib. c lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (CFLAGS) liolib. c
Llex. obj: llex. c lua. h luaconf. h LDC. h lobject. h llimits. h lstate. h ltm. h/
Lzio. h lmem. h llex. h lparser. h lstring. h lgc. h ltable. h
$ (CC) $ (CFLAGS) llex. c
Lmathlib. obj: lmathlib. c lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (CFLAGS) lmathlib. c
Lmem. obj: lmem. c lua. h luaconf. h ldebug. h lstate. h lobject. h llimits. h/
Ltm. h lzio. h lmem. h LDC. h
$ (CC) $ (CFLAGS) lmem. c
Loadlib. obj: loadlib. c lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (CFLAGS) loadlib. c
Lobject. obj: lobject. c lua. h luaconf. h LDC. h lobject. h llimits. h lstate. h/
Ltm. h lzio. h lmem. h lstring. h lgc. h lvm. h
$ (CC) $ (CFLAGS) lobject. c

>
Lopcodes. obj: lopcodes. c lopcodes. h llimits. h lua. h luaconf. h
$ (CC) $ (CFLAGS) lopcodes. c
Loslib. obj: loslib. c lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (CFLAGS) loslib. c
Lparser. obj: lparser. c lua. h luaconf. h lcode. h llex. h lobject. h llimits. h/
Lzio. h lmem. h lopcodes. h lparser. h ldebug. h lstate. h ltm. h drop-down. h/
Lfunc. h lstring. h lgc. h ltable. h
$ (CC) $ (CFLAGS) lparser. c
Lstate. obj: lstate. c lua. h luaconf. h ldebug. h lstate. h lobject. h llimits. h/
Ltm. h lzio. h lmem. h LDC. h lfunc. h lgc. h llex. h lstring. h ltable. h
$ (CC) $ (CFLAGS) lstate. c
Lstring. obj: lstring. c lua. h luaconf. h lmem. h llimits. h lobject. h lstate. h/
Ltm. h lzio. h lstring. h lgc. h
$ (CC) $ (CFLAGS) lstring. c
Lstrlib. OBJ: lstrlib. c Lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (cflags) lstrlib. c
Ltable. OBJ: ltable. c Lua. h luaconf. h ldebug. h lstate. h lobject. h llimits. h/
Ltm. h lzio. h lmem. h lgc. h ltable. h
$ (CC) $ (cflags) ltable. c
Ltablib. OBJ: ltablib. c Lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (cflags) ltablib. c
Ltm. OBJ: ltm. c Lua. h luaconf. h lobject. h llimits. h lstate. h ltm. h lzio. h/
Lmem. h lstring. h lgc. h ltable. h
$ (CC) $ (cflags) ltm. c
Lua. OBJ: Lua. c Lua. h luaconf. h lauxlib. h lualib. h
$ (CC) $ (cflagsexe) Lua. c
Luac. OBJ: luac. c Lua. h luaconf. h lauxlib. h drop-down. h lobject. h llimits. h/
Lstate. h ltm. h lzio. h lmem. h lfunc. h lopcodes. h lstring. h lgc. h/
Lundump. h
$ (CC) $ (CFLAGSEXE) luac. c

Lundump. obj: lundump. c lua. h luaconf. h ldebug. h lstate. h lobject. h/
Llimits. h ltm. h lzio. h lmem. h drop-down. h lfunc. h lstring. h lgc. h lundump. h
$ (CC) $ (CFLAGS) lundump. c

Lvm. obj: lvm. c lua. h luaconf. h ldebug. h lstate. h lobject. h llimits. h ltm. h/
Lzio. h lmem. h LDC. h lfunc. h lgc. h lopcodes. h lstring. h ltable. h lvm. h
$ (CC) $ (CFLAGS) lvm. c

Lzio. obj: lzio. c lua. h luaconf. h llimits. h lmem. h lstate. h lobject. h ltm. h/
Lzio. h
$ (CC) $ (CFLAGS) lzio. c

Print. obj: print. c ldebug. h lstate. h lua. h luaconf. h lobject. h llimits. h/
Ltm. h lzio. h lmem. h lopcodes. h lundump. h
$ (CC) $ (CFLAGSEXE) print. c

# (End of Makefile)

Article Source: DIY tribe (http://www.diybl.com/course/3_program/c++/cppjs/2008224/100888.html)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.