2021-11-27 有关项目编译的学习 Xmake -1- 安装

学习C++,遇到不少的编译问题,用gcc工具链和mingw工具链,如果有多文件项目,编译是个大问题。

所以最近学习了一下 Xmake,这个确实是国人开发的项目编译之光,对我来说,太有吸引力。

有原生中文文档,基于lua生成xmake file,容易看懂。

把复杂的事情简单化,很牛。

安装:

在windows系统下,我用msys2管理工具,可直接 " pacman -Ss xmake "

//查包
$ pacman -Ss xmake
mingw32/mingw-w64-i686-xmake 2.5.9-1
    A cross-platform build utility based on Lua (mingw-w64)
mingw64/mingw-w64-x86_64-xmake 2.5.9-1 [installed]
    A cross-platform build utility based on Lua (mingw-w64)
ucrt64/mingw-w64-ucrt-x86_64-xmake 2.5.9-1
    A cross-platform build utility based on Lua (mingw-w64)
clang64/mingw-w64-clang-x86_64-xmake 2.5.9-1
    A cross-platform build utility based on Lua (mingw-w64)

//完成安装
$ pacman -S mingw-w64-x86_64-xmake

我的Linux系统是通过wsl2虚拟的Debian,没有现成的apt安装包,只能网站下载deb安装包:


https://github.com/xmake-io/xmake/releases
xmake-v2.5.9.amd64.deb
//安装
dpkg -i xmake-xxxx.deb

如果是Ubuntu 可以


sudo apt-get install software-properties-common
sudo add-apt-repository ppa:xmake-io/xmake
sudo apt update
sudo apt install xmake

我是用vscode,可以简单的配合xmake,因为有插件,在vscode的应用商店插件扩展搜素xmake,下载即可。

xmake的配置,在xmake扩展选项或在settings.json中设置:

我在window+mingw下的配置:

//--cxx=g++ 编译器为g++
//--plat=mingw 平台为mingw
//--arch=x86_64 处理器架构为x86_64
    "xmake.additionalConfigArguments": "--cxx=g++ --plat=mingw --arch=x86_64 ",
    "xmake.workingDirectory": "${workspaceRoot}/project/",
    "xmake.buildDirectory": "${workspaceRoot}/project/build",
    "xmake.compileCommandsDirectory": "${workspaceRoot}/.vscode",

Debian+gcc下的配置:

    "xmake.additionalConfigArguments": "--cxx=g++ --plat=linux --arch=x86_64 ",
    "xmake.workingDirectory": "${workspaceRoot}/project/",
    "xmake.buildDirectory": "${workspaceRoot}/project/build",
    "xmake.compileCommandsDirectory": "${workspaceRoot}/.vscode",

使用的时候非常简单,在vscode中设置一个project文件夹,

把项目文件都移到这个文件夹下,

按F1,调出命令面板, 输入xmake 选择install,

xmake会自动搜索构建编译环境文件,

并要求新建一个xmake.lua文件,用于手动调整编译参数,添加include地址,lib地址,lib文件,cxxflag等等。

add_rules("mode.debug", "mode.check") //添加规则,debug是用于gdb调试,
                                      //check是用于sanitize内存检测
target("deletePtr")          //生成文件
    set_kind("binary")       //文件类型,二进制可执行文件
    add_files("deletePtr.cpp")  //原文件名
    add_cxxflags("-fsanitize=address","-ftrapv")  //内存检测编译参数
    add_ldflags("-fsanitize=address")             //内存检测连接参数

就这样吧, 然后F1 xmake build, 愉快的看着终端中的构建过程,

大概可以80%的工作交由xmake完成,

有疑问可以参考官方文档, 要深入研究还是有挺多东西要学习的, 比如依赖管理, 这个大坑.

https://xmake.io/#/zh-cn/guide/installation

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不停感叹的老林_<C 语言编程核心突破>

不打赏的人, 看完也学不会.

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值