使用xmake编译工程

发布于:2023-03-12 ⋅ 阅读:(913) ⋅ 点赞:(0)

如果你只想编译当前主机环境的平台,例如在windows上编译windows版本,在macosx上编译macosx版本,那么你只需要敲以下命令即可:

xmake

因为xmake默认会去检测当前的环境,默认编译当前主机的平台版本,不需要做额外的配置,并且默认编译的是release版本。

如果工程里面有多个目标,那么上面的命令,会去编译所有目标,如果只想编译指定一个目标,例如:test,那么只需执行:

xmake test

如果你想编译debug版本,那么需要做些简单的配置:

xmake config --mode=debug
xmake

xmake针对每个命令和参数,都提供了简写版本:

xmake f -m debug
xmake

注:为了提高灵活性,release版本和debug版本的编译选项设置,需要自己在工程描述文件中描述,如果没有设置的话,release和debug版本生成的程序是一样的。

如果你想强制重新构建所有,可以执行:

xmake -r
xmake --rebuild

如果要指定编译具体某个架构,可以这么进行编译:

xmake f -a armv7
xmake

一般情况下,如果没有指定架构,默认会去使用指定平台的默认架构,例如:macosx下默认是x86_64,iphoneos下士armv7

如果想要指定编译其他平台,例如在macosx上编译iphoneos的版本,那么:

xmake f -p iphoneos
xmake

编译android版本:

xmake f -p android --ndk=xxxx
xmake

虽然配置完后,每次编译不需要重新配置,但是如果切换编译目标平台到ios、linux,那么之前ndk的设置就被清除了,下次得重新配置。

如果想要更加方便的不同平台间来回切换编译,可以将ndk设置到全局配置中,例如:

-- 将ndk设置到全局配置中
xmake g --ndk=xxx

-- 切换到android编译平台,不需要每次都设置ndk了
xmake f -p android
xmake -r

-- 切换到ios编译平台
xmake f -p iphoneos
xmake -r

编译windows版本,很简单,只要你机子装了vs,xmake会去自动检测,不需要做额外的配置,只需要打开cmd,进入你的工程目录,
然后执行xmake就行了。

使用其他交叉工具链进行编译:

xmake f -p android -a armv7-a --cross=arm-linux-androideabi- --toolchains=/xxxx/bin
xmake

默认在编译配置的时候,会去缓存上一次的配置,这样每次配置只需要修改部分参数就行了,不需要每次全部重新配置

如果你想重新配置所有,清楚原有的缓存,可以加上--clean参数:

xmake f -c
xmake f --clean
xmake

xmake在配置的时候,会去检测工程依赖的一些接口和链接库,如果你想要看具体详细的配置检测信息,可以加上--verbose参数,回显配置信息

xmake f -c -v
xmake f --clean --verbose
xmake

xmake还支持在编译的时候,手动设置一些编译选项和工具,具体参数列表如下:

--cc=CC                            The C Compiler
--cxx=CXX                          The C++ Compiler
--cflags=CFLAGS                    The C Compiler Flags
--cxflags=CXFLAGS                  The C/C++ compiler Flags
--cxxflags=CXXFLAGS                The C++ Compiler Flags
                                           
--as=AS                            The Assembler
--asflags=ASFLAGS                  The Assembler Flags
                                           
--ld=LD                            The Linker
--ldflags=LDFLAGS                  The Binary Linker Flags
                                           
--ar=AR                            The Static Library Linker
--arflags=ARFLAGS                  The Static Library Linker Flags
                                           
--sh=SH                            The Shared Library Linker
--shflags=SHFLAGS                  The Shared Library Linker Flags
                                           
--mm=MM                            The Objc Compiler
--mxx=MXX                          The Objc++ Compiler
--mflags=MFLAGS                    The Objc Compiler Flags
--mxflags=MXFLAGS                  The Objc/c++ Compiler Flags
--mxxflags=MXXFLAGS                The Objc++ Compiler Flags

本文含有隐藏内容,请 开通VIP 后查看