note/专业积累/工具/xmake/xmake 使用.md
2023-07-05 09:34:06 +08:00

246 lines
4.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安装
## xmake
构建工具
[github](https://github.com/xmake-io/xmake/releases)
## clang
c++ 编译器
[github](https://github.com/llvm/llvm-project/releases)
## VS CODE
[https://zhuanlan.zhihu.com/p/398790625](https://zhuanlan.zhihu.com/p/398790625)
[万字长文]Visual Studio Code 配置 C/C++ 开发环境的最佳实践(VSCode + Clangd + XMake)
## 配置
强行修改 xmake.conf
通过 xmake f 设置会失败
```shell
--全局配置
xmake g --ndk=~/files/android-ndk-r10e/
--清除配置
xmake f -c
--导出配置
xmake f --export=config.txt
xmake f -m debug --xxx=y --export=config.txt
--环境变量
xmake show -l envs
```
# 项目
## 更新
```shell
# 更新到指定版本
xmake update 2.2.4
#更新到指定分支
xmake update master
xmake update dev
#更新到指定地址
xmake update github:xmake-io/xmake#master
#更新脚本
xmake update -s dev
#卸载
xmake update --uninstall
```
## 创建
```shell
#创建
xmake create zmake
#查询创建模板
xmake create --help
#创建指定模板 语言 + 类型
xmake create -l c -t static zmake
xmake create -t qt.quickapp zmake
xmake create -l cuda test
#指定编译版本
xmake f -m debug
#清除缓存
xmake f -c
```
## 编译
```shell
# 使用帮助
xmake f --help
# 设置编译架构
xmake f -p android --ndk=xxx -a arm64-v8a
# 交叉编译
xmake f -p cross --sdk=/home/toolchains_sdkdir
xmake f -p linux --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin
xmake f -p linux --sdk=/user/toolsdk --cc=armv7-linux-clang --cxx=armv7-linux-clang++
# 设置目录
xmake f -p linux --sdk=/usr/toolsdk --includedirs=/usr/toolsdk/xxx/include --linkdirs=/usr/toolsdk/xxx/lib --links=pthread
```
## 生成
```shell
# 生成 vs 项目
xmake project -k vsxmake
# 指定版本 与 模式
xmake project -k vsxmake2022 -m "debug;release"
```
## 运行
```shell
#编译
xmake
#运行程序
xmake run
#触发事件
on_run
```
## 调试
```shell
#输出调试信息
#v 输出 编译指令
xmake -vD
xmake -vD verbose Diagnosis
# 语法检测
xmake check
xmake check api
xmake check api.target
xmake check -v
# 自动修复
xmake check clang.tidy --fix
```
## 调试Lua源码
```lua
local _luasocket = _PROGRAM_DIR .. "/winenv/bin/core.dll"
package.cpath = package.cpath .. ";" .. _luasocket
require("../winenv/bin/LuaPanda").start("127.0.0.1",8818)
```
## 下载
关闭 curl ssl 证书验证
```shell
xmake global --help
xmake global --insecure-ssl=INSECURE-SSL
```
# Lua 接口
```shell
xmake lua /tmp/test.lua
xmake lua lib.detect.find_tool gcc
xmake lua
进入lua 交互
```
# 第三方库
## 本地依赖
```shell
# -p android 指定编译平台
# 传递库名 与 编译路径
xmake f -p android --ndk=~/downloads/android-ndk-r19c
xmake f --qt=/home/xxx/qtsdk
```
## 全局依赖
```shell
# 传递库名 与 编译路径
xmake g --ndk=~/xxx/android-ndk-r19c
xmake g --qt=/home/xxx/qtsdk
```
## 示例
```shell
xmake f -p android --ndk=xxx --ndk_sdkver=16
xmake f -p android --ndk=xxx -a arm64-v8a
xmake f -p android --ndk=xxxx --ndk_cxxstl=gnustl_shared
xmake f -p android --ndk=xxxx --ndk_cxxstl=gnustl_shared --ndk_sdkver=16
xmake f --help
```
# QA
## xmake f
强行修改 `.xmake\windows\xmake.conf`
`xmake f -a=x64 -p=windows`
xmake f -cvD
## add_requires
pulling repository(build-artifacts): https://github.com/xmake-mirror/build-artifacts.git to C:\Users\Administrator\AppData\Local\.xmake\repositories\build-artifacts ..
git -c core.fsmonitor=false pull origin main
fatal: not a git repository (or any of the parent directories): .git
error: execv(git -c core.fsmonitor=false pull origin main) failed(128)
手动 git clone [https://github.com/xmake-mirror/build-artifacts.git](https://github.com/xmake-mirror/build-artifacts.git)
## curl ssl problem
由cartalyst / stripe使用的Guzzle将执行以下操作来查找适当的证书归档以检查服务器证书是否符合以下条件
1. 检查你的php.ini文件是否设置了`openssl.cafile` 。
2. 检查`curl.cainfo`是否在您的php.ini文件中设置。
3. 检查是否存在`/etc/pki/tls/certs/ca-bundle.crt` HatCentOSFedora;由ca-certificates包提供
4. 检查`/etc/ssl/certs/ca-certificates.crt`存在UbuntuDebian;由ca-certificates包提供
5. 检查`/usr/local/share/certs/ca-root-nss.crt`存在FreeBSD;由ca_root_nss包提供
6. 检查`/usr/local/etc/openssl/cert.pem` X;由homebrew提供
7. 检查是否存在`C:\windows\system32\curl-ca-bundle.crt` Windows
8. 检查是否存在`C:\windows\curl-ca-bundle.crt` Windows
https://curl.haxx.se/docs/caextract.html
curl-ca-bundle.crt
## curl 慢
连 strong vpn 就行