Xmake介绍和使用

发布时间 2023-07-06 21:27:39作者: 啊唯0o

@

介绍

Xmake 是一个基于 Lua 语言的跨平台构建工具,用于快速、简单地构建和管理 C/C++ 项目。它提供了简洁的语法和丰富的功能,可以处理常见的项目构建需求,包括编译、链接、测试、安装等。Xmake 的设计目标是提供一种轻量级、易于使用的构建解决方案,适用于各种规模的项目和不同的操作系统平台,如 Windows、Linux 和 macOS 等。

作用

通过Xmake,开发人员可以通过简单的命令行操作,快速构建并管理他们的项目。同时,它还支持模块化构建、插件扩展等特性,方便用户根据具体需求进行定制和扩展。总之,Xmake 是一个功能强大、易用的构建工具,可以帮助开发人员提高项目构建效率。

安装

Windows系统

使用安装包下载,通过 xmake-dev.win64.exe 下载对应的EXE文件,下载完成后,直接一直下一步,直到完成即可。

Linux系统

使用apt安装

sudo add-apt-repository ppa:xmake-io/xmake
sudo apt update
sudo apt install xmake

使用

创建项目

找个一个空的文件夹,打开命令行,输入 xmake create hello, 会生成一个hello world 工程

$ xmake create hello
create hello ...
  [+]: src/main.cpp
  [+]: xmake.lua
  [+]: .gitignore
create ok!

配置编译工具

设置gcc工具: xmake f --toolchain=gcc

F:\other\xmake_test>xmake f --toolchain=gcc
checking for platform ... windows
checking for architecture ... x64

项目编译

编译:xmake

F:\other\xmake_test>xmake
[ 25%]: cache compiling.release src\main.cpp
[ 25%]: cache compiling.release src\main.cpp
[ 50%]: linking.release hello.exe
[100%]: build ok, spent 1.328s

项目运行

F:\other\xmake_test>xmake run
hello world!

官网教程

对应的官网教程xmake-教程

问题

error: cannot execv(nmake ), No such file or directory

img
在该目录下创建一个xmake.lua文件

set_config("toolchain", "gcc") -- 默认使用gcc进行编译
add_rules("mode.debug", "mode.release")

target("c_test")
    set_kind("binary")

error: g++: fatal error: no input files

[ 33%]: linking.release c_test.exe
error: g++: fatal error: no input files
compilation terminated.