2024年6月21日,华为仓颉正式公开发布。
不少同学看过仓颉白皮书后,都在找SDK从哪下载,HelloWorld怎么跑。仓颉公众号也及时发布了内测的方式,我也亲自走了一遍整个流程,
一,申请内测
关注“仓颉编程语言”微信公众号,回复“SDK”关键词,填写内测申请问卷(姓名、邮箱、gitcode地址等)。【建议提前注册gitcode,github可直接授权登录】
接下来就是等待邮件回复,2-3个工作日,
管理审核成功后,即可访问仓颉社区:仓颉SDKGitCode是面向全球开发者的开源社区,包括原创博客,开源代码托管,代码协作,项目管理等。与开发者社区互动,提升您的研发效率和质量。https://gitcode.com/Cangjie 仓颉支持VSCode开发环境,社区提供了VSCode插件CangjieVSCodePlugin
,以及Linux/Windows/MacOS版本的SDK。
二,环境搭建
2.1 Windows平台搭建仓颉环境
2.1.1 下载SDK
从你送到的邮箱里面点击Windows版本的仓颉lSDK链接
点击exe或者 zip都行,exe需要安装,zip解压可用
我这里用的zip,直接解压
2.1.2 安装,配置系统环境
2.1.2.1 exe安装
如果你下载的SDK是exe格式,直接点击安装就好,安装时会自动将所需环境变量配置好。
选 all user
2.1.2.2 zip 解压 配置环境变量
我这里的解压到 E:\cangjie\cangjieSDK\
右键 我的电脑---->属性---->高级系统设置---->环境变量
然后找到下方 系统变量---->双击Path
将
E:\cangjie\cangjieSDK\bin
E:\cangjie\cangjieSDK\tools\bin
添加到环境变量
遇到环境变量超过2047 请参考《解决:此环境变量太大。此对话框允许将值设置为最长2047个字符-CSDN博客》
然后用 命令行工具测试下
C:\Users\Administrator>cjc --help
Usage:cjc [option] file...Options:--diagnostic-format <value> Diagnostic format. Candidate modes:<value>=json<value>=noColor<value>=default--scan-dependency Get the package(s) which the current package depends on--conditional-compilation-config <value>User defined contion to compile--debug-macro Enable debug macro--parallel-macro-expansion Enable parallel macro expansion-g Enable compile debug version target--trimpath <value> Remove a specified path prefix in debuginfo-s, --strip-all Strip the symbol table from executable and dynamic library--test Enable compile test--mock <value> Specify whether mock features are enabled, or disabled, or a runtime exception is thrown when trying to use mock features<value>=on<value>=off<value>=runtime-error-o, --output <value> Specify product name or output directory when compiling a package--output-dir <value> Specify output directory (it affects '--output' option)--static-std Statically link packages of the std module--dy-std Dynamically link packages of the std module--static-libs Statically link packages of other modules except std--dy-libs Dynamically link packages of other modules except std--lto <value> Enable LTO to either 'full' or 'thin'<value>=full<value>=thin--enable-ad, --enable-auto-differentiationEnables automatic differentiation--enable-chir2-devirtualizationEnable CHIR 2 devirtualization.--enable-opaque Enable opaque pointer--fchir-constant-propagationEnable constant propagation optimizaion in CHIR--fno-chir-constant-propagationDisable constant propagation optimizaion in CHIR--fchir-function-inlining Enable function inlining optimizaion in CHIR--fno-chir-function-inliningDisable function inlining optimizaion in CHIR--fchir-devirtualization Enable devirtualization optimizaion in CHIR--fno-chir-devirtualization Disable devirtualization optimizaion in CHIR--sanitizer-coverage-inline-8bit-countersEnable sanitizer-coverage-inline-8bit-counters in CHIR--sanitizer-coverage-inline-bool-flagEnable sanitizer-coverage-inline-bool-flag in CHIR--sanitizer-coverage-trace-pc-guardEnable sanitizer-coverage-trace-pc-guard in CHIR--sanitizer-coverage-pc-tableEnable sanitizer-coverage-pc-table in CHIR--sanitizer-coverage-stack-depthEnable sanitizer-coverage-stack-depth in CHIR--sanitizer-coverage-trace-comparesEnable sanitizer-coverage-trace-compares in CHIR--sanitizer-coverage-trace-memcmpEnable sanitizer-coverage-trace-memcmp in CHIR--sanitizer-coverage-level=0sancov level 0--sanitizer-coverage-level=1sancov level 1--sanitizer-coverage-level=2sancov level 2--sanitizer-coverage-level <value>Set sanitizer-coverage level--int-overflow <value> Specify default integer overflow strategy:<value>=throwing<value>=wrapping<value>=saturating--fast-math Enable fast-math mode--link-options <value> Options directly passed to linker-L, --library-path <value> Add directory to library search path-l, --library <value> Link library-B, --toolchain <value> Use toolchain binaries and object files at the given directory--target <value> Generate code for the given target platform--target-cpu <value> Generate instructions for the given target processor (Experimental)--sysroot <value> Set the system root directory under which bin, lib and include can be found--output-type <value> Specify output file type<value>=exe emit executable (default)<value>=staticlib emit static library<value>=dylib emit dynamic library-O0 Optimization level 0 (default)-O, -O1 Optimization level 1-O2 Optimization level 2-Os Optimization level s, like -O2 with extra optimizations for size-Oz Optimization level z, like -Os but reduces code size further-O<value> Set Optimization level--module-name <value> Tell compiler name of the module-p, --package Specify package directory to be compiled--import-path <value> Add .cjo search path--incremental-compile Enable incremental compilation.--save-temps <value> Save intermediate compilation results. <value>: path to save temp files.-Woff, --warn-off <value> Suppress a specific group of warning<value>=all<value>=unused<value>=driver-arg<value>=deprecated<value>=unsupport-compile-source<value>=package-import<value>=parser<value>=semantics<value>=interpreter-Won, --warn-on <value> Report a specific group of warning<value>=all<value>=unused<value>=driver-arg<value>=deprecated<value>=unsupport-compile-source<value>=package-import<value>=parser<value>=semantics<value>=interpreter--error-count-limit <value> Emit specified <number> of errors only. Available options: all, <number> (8 by default)-V, --verbose Enable verbose-v, --version Print compiler version information-h, --help Show usage--macro-lib <value> Options directly passed to macro library, put the value into "" when there is space in it--compile-macro Options to compile the macro define package--coverage Enable coverage--experimental Enable experimental options-j, --jobs <value> Number of tasks to run at once--apc, --aggressive-parallel-compileEnable agrressive parallel compile--sanitize <value> Enable sanitizer:<value>=address<value>=thread--fobf-string Enable string literal obfuscation--fno-obf-string Disable string literal obfuscation--fobf-const Enable constant literal obfuscation--fno-obf-const Disable constant literal obfuscation--fobf-layout Enable code layout obfuscation--fno-obf-layout Disable code layout obfuscation--fobf-cf-flatten Enable control flow flatten obfuscation--fno-obf-cf-flatten Disable control flow flatten obfuscation--fobf-cf-bogus Enable control flow bogus obfuscation--fno-obf-cf-bogus Disable control flow bogus obfuscation--fobf-all Enable all obfuscations--obf-config <value> Specify obfuscation configure file--obf-level <value> Specify obfuscation level. Available value: 1 to 10 (5 by default)--obf-seed <value> Specify random seed for obfuscation algorithm. Available value: <number>--disable-reflection Disable reflection--stack-trace-format <value>Specify stack trace format<value>=default<value>=simple<value>=all--pgo-instr-gen PGO instrumentation--pgo-instr-use <value> Read PGO instrumentation profile--discard-eh-frame Discard the eh_frame section
三,开发编译测试
代码hello.cj
main() {println("你好,仓颉")
}
编译
cjc hello.cj -o hello.out
运行
汉字编码有问题,我们后面学习在研究,先换成英文的试试
main() {println("hello cangjie")
}
参考资料
- 仓颉官网:仓颉-鸿蒙原生应用编程语言-华为开发者联盟
- 仓颉社区:GitCode - 全球开发者的开源社区,开源代码托管平台
- 仓颉编程语言白皮书:文档中心