赞
踩
2024年6月21日,华为仓颉正式公开发布。
不少同学看过仓颉白皮书后,都在找SDK从哪下载,HelloWorld怎么跑。仓颉公众号也及时发布了内测的方式,我也亲自走了一遍整个流程,
关注“仓颉编程语言”微信公众号,回复“SDK”关键词,填写内测申请问卷(姓名、邮箱、gitcode地址等)。【建议提前注册gitcode,github可直接授权登录】
接下来就是等待邮件回复,2-3个工作日,
管理审核成功后,即可访问仓颉社区:仓颉SDKGitCode是面向全球开发者的开源社区,包括原创博客,开源代码托管,代码协作,项目管理等。与开发者社区互动,提升您的研发效率和质量。https://gitcode.com/Cangjie 仓颉支持VSCode开发环境,社区提供了VSCode插件CangjieVSCodePlugin
,以及Linux/Windows/MacOS版本的SDK。
从你送到的邮箱里面点击Windows版本的仓颉lSDK链接
点击exe或者 zip都行,exe需要安装,zip解压可用
我这里用的zip,直接解压
如果你下载的SDK是exe格式,直接点击安装就好,安装时会自动将所需环境变量配置好。
选 all user
我这里的解压到 c:\cangjie\
右键 我的电脑---->属性---->高级系统设置---->环境变量
然后找到下方 系统变量---->双击Path
将
c:\cangjie\bin
c:\cangjie\tools\bin
c:\cangjie\runtime\lib\windows_x86_64_llvm
c:\cangjie\debugger\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-differentiation
- Enables automatic differentiation
- --enable-chir2-devirtualization
- Enable CHIR 2 devirtualization.
- --enable-opaque Enable opaque pointer
- --fchir-constant-propagation
- Enable constant propagation optimizaion in CHIR
- --fno-chir-constant-propagation
- Disable constant propagation optimizaion in CHIR
- --fchir-function-inlining Enable function inlining optimizaion in CHIR
- --fno-chir-function-inlining
- Disable function inlining optimizaion in CHIR
- --fchir-devirtualization Enable devirtualization optimizaion in CHIR
- --fno-chir-devirtualization Disable devirtualization optimizaion in CHIR
- --sanitizer-coverage-inline-8bit-counters
- Enable sanitizer-coverage-inline-8bit-counters in CHIR
- --sanitizer-coverage-inline-bool-flag
- Enable sanitizer-coverage-inline-bool-flag in CHIR
- --sanitizer-coverage-trace-pc-guard
- Enable sanitizer-coverage-trace-pc-guard in CHIR
- --sanitizer-coverage-pc-table
- Enable sanitizer-coverage-pc-table in CHIR
- --sanitizer-coverage-stack-depth
- Enable sanitizer-coverage-stack-depth in CHIR
- --sanitizer-coverage-trace-compares
- Enable sanitizer-coverage-trace-compares in CHIR
- --sanitizer-coverage-trace-memcmp
- Enable sanitizer-coverage-trace-memcmp in CHIR
- --sanitizer-coverage-level=0
- sancov level 0
- --sanitizer-coverage-level=1
- sancov level 1
- --sanitizer-coverage-level=2
- sancov 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-compile
- Enable 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
Cangjie
插件安装在这个链接中下载VS Code的插件。下载下来并解压。得到一个Cangjie-0.51.4.vsix
文件,之后会用到。
打开VS Code,如图点击左侧Extensions -> Views and More Actions -> Install from VSIX,找到刚才解压出来的Cangjie-0.51.4.vsix
文件。安装成功。
开发环境搭建完成。
在VS Code界面中使用快捷键ctrl + shift + p
在搜索框里输入关键字搜索Create Cangjie Project
并选择
下一步选择Create CJNative Cangjie Project
选择Create Executable Output Cangjie Project
在弹出的文件夹选择窗里选择工程存放的目录
回到之前界面,在上方输入框中输入工程的名称,并回车
在左侧目录结构中找到src -> main.cj
可以看到默认创建的一段helloworld代码
main.cj 内容
- main(): Int64 {
- println("hello world")
- return 0
- }
cjpm.toml 内容
- [dependencies]
-
- [package]
- cjc-version = "0.51.4"
- compile-option = ""
- description = "nothing here"
- link-option = ""
- name = "HelloTest"
- output-type = "executable"
- src-dir = ""
- target-dir = ""
- version = "1.0.0"
- package-configuration = {}
代码 main.cj 我们用中文试试
- main() {
- println("你好,仓颉")
- }
运行
汉字编码有问题,暂时的解决方案是运行chcp 65001命令
chcp 65001
再次运行
cjpm run
- main() {
- println("hello cangjie")
- }
编译
cjc hello.cj -o hello.out
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。