【Lua C交互】1 - Premake 生成编译工程

2 篇文章 0 订阅

本文主要通过Premake4生成编译工程来于快速编译出 C与lua交互 使用的库和可执行文件。

 

工具: Premake4 

开源代码: Lua-5.2.4  src目录下所有文件

本专题【C与lua交互】中使用的代码:myclua.c  ,  c_lib1.c    ,  c_lib2.c

 

Premake4 生成编译工程的配置文件如下:

-- premake4.lua
-- >premake4 --file=premake4.lua --os=windows  vs2012
-- >premake4 --file=premake4.lua --os=linux --platform=x64 gmake
-- > devenv c_lib_for_lua.sln /build "Release|Win32"

solution 'c_lib_for_lua'
    configurations {'Debug', 'Release'}
    platforms {'x32', 'x64'}

	configuration "Debug"
    targetdir "debug/bin"
	objdir "debug/obj"

	if os.get() == "windows" then
        defines '_CRT_SECURE_NO_WARNINGS'
    end

    configuration "Release"
    targetdir "release/bin"
	objdir "release/obj"

	if os.get() == "windows" then
        defines '_CRT_SECURE_NO_WARNINGS'
    end

    -- the lua library
    project 'lualibd'
        targetname 'lualibd' -- rename the target library to lua
        kind 'SharedLib'
        language 'C'
		if os.get() == "windows" then
			defines {'LUA_BUILD_AS_DLL'}
		end
        files {'./*.c'}
	    excludes { "./lua.c", "./luac.c" ,'./myclua.c','./c_lib1.c','./c_lib2.c'}
		
	-- the lua interpret
    project 'lua'
        kind 'ConsoleApp'
        language 'C'
        links 'lualibd'
        if os.get() == "linux" then
            links {'m'}
		else 
			defines {'_CRT_SECURE_NO_WARNINGS'}
        end
        files {"./lua.c"}
		
	project 'c_lib1'
        targetname 'c_lib1'
        kind 'ConsoleApp'
        language 'C'
		if os.get() == "windows" then
			defines {'_Win32'}
		end
		links {"lualibd"}
		includedirs {"./"}
        files {'./c_lib1.c'}
		

    -- the lua library
    project 'mytestlib'
        targetname 'mytestlib'
        kind 'SharedLib'
        language 'C'
		if os.get() == "windows" then
			defines {'_Win32'}
		end
		links {"lualibd"}
		includedirs {"./"}
        files {'./c_lib2.c'}
		
		 

		    
    project 'myclua'
        targetname 'myclua' 
        kind 'ConsoleApp'
        language 'C'
		if os.get() == "windows" then
			defines {'_Win32'}
		end
		links {"lualibd"}
		includedirs {"./"}
        files {'./myclua.c'}

 

使用premake4.exe 加上述配置文件来生成Window 下VS编译工程(Linux GCC 也可以)进行编译。

VS命令行执行

1 >premake4 --file=premake4.lua --os=windows  vs2012

2 > devenv c_lib_for_lua.sln /build "Release|Win32"

 

之后在目录release/bin下就生成了可执行文件和库

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值