Swift Research 01-run Swift program with SWITFC Terminal Command compilation

Source: Internet
Author: User
Tags emit



At the request of the company, I studied the swift language and then gave you swift technical training, bought 4, 5 swift related books began to study.



To introduce today, SWFT related terminal commands.



1. First we build a swift folder on the desktop for storing. Swift source files,



Open terminal input CD plus space drag folder to terminal (using command ls, CD directory is also equivalent)





Cd/users/mac/desktop/swfit
</ pre> <p> </ p> <p> 2. To create, compile, and run swift source files, you need to use the swiftc command with the relevant options parameters. </ p> <p> Here we take a look, Related parameters and usage of swiftc, </ p> <p> Enter swiftc --help to see the following parameters. You can use the swiftc command according to the following comments. </ p> <p> </ p> < pre name = "code" class = "objc"> yangbindeMacBook-Air: swfit mac $ swiftc --help
OVERVIEW: Swift compiler

USAGE: swiftc [options] <inputs>

MODES:
  -dump-ast Parse and type-check input file (s) and dump AST (s)
  -dump-parse Parse input file (s) and dump AST (s)
  -emit-assembly Emit assembly file (s) (-S)
  -emit-bc Emit LLVM BC file (s)
  -emit-executable Emit a linked executable
  -emit-ir Emit LLVM IR file (s)
  -emit-library Emit a linked library
  -emit-object Emit object file (s) (-c)
  -emit-silgen Emit raw SIL file (s)
  -emit-sil Emit canonical SIL file (s)
  -parse Parse input file (s)
  -print-ast Parse and type-check input file (s) and pretty print AST (s)

OPTIONS:
  -application-extension Restrict code to those available for App Extensions
  -assert-config <value> Specify the assert_configuration replacement. Possible values are Debug, Release, Replacement.
  -D <value> Specify one or more build configuration options
  -emit-dependencies Emit Make-compatible dependencies files
  -emit-module-path <path>
                          Emit an importable module to <path>
  -emit-module Emit an importable module
  -emit-objc-header-path <path>
                          Emit an Objective-C header file to <path>
  -emit-objc-header Emit an Objective-C header file
  -framework <value> Specify a framework which should be linked against
  -F <value> Add directory to framework search path
  -g Emit debug info
  -help Display available options
  -import-underlying-module
                          Implicitly imports the Objective-C half of a module
  -I <value> Add directory to the import search path
  -j <n> Number of commands to execute in parallel
  -L <value> Add directory to library link search path
  -l <value> Specify a library which should be linked against
  -module-cache-path <value>
                          Specify the Clang module cache path
  -module-link-name <value>
                          Library to link against when using this module
  -module-name <value> Name of the module to build
  -nostdimport Don't search the standard library import path for modules
  -Onone Compile without any optimization
  -Ounchecked Compile with optimizations and remove runtime safety checks
  -output-file-map <path> A file which specifies the location of outputs
  -O Compile with optimizations
  -o <file> Write output to <file>
  -parse-as-library Parse the input file (s) as libraries, not scripts
  -parse-sil Parse the input file as SIL code, not Swift source
  -parseable-output Emit textual output in a parseable format
  -save-temps Save intermediate compilation results
  -sdk <sdk> Compile against <sdk>
  -serialize-diagnostics Serialize diagnostics in a binary format
  -target-cpu <value> Generate code for a particular CPU variant
  -target <value> Generate code for the given target
  -version Print version information and exit
  -v Show commands to run and use verbose output
  -Xcc <arg> Pass <arg> to the C / C ++ / Objective-C compiler
  -Xlinker <value> Specify an option which should be passed to the linker 





3. Create a hello.swft source file using the VI command


After entering the Swift folder, then use the following command to create





VI Helloworld.swift
Then create the code in the text and print out the HelloWorld







println ("Hello this is my first Swift program!")
Then press the ESC key once, Shfit + semicolon key, then enter WQ, return





Save and Launch VI



4. Then, in the Swift directory, compile the swift source file, using the Swiftc-o parameter





Swiftc-o Hello.out Helloworld.swift
You can see a file with an. Out suffix generated in the Swift directory

Hello.out is the type of output file, a program that can be executed directly on a Mac and can be run using terminal



For example, drag the. out file directly to the terminal, then enter to see that the terminal executed the file and the output is as follows:





Hello This is my first Swift program!
It can also be executed directly using the./hello.out in the Swift directory, the effect is equivalent







./hello.out

Note that you will not perform the direct use of hello.out under the current directory Swift, as the system will not look in the current directory

This completes, using the terminal to compile the swift source program, [OS x platform]



Of course we can use playground to replace some simple program tests.


Original from Http://blog.csdn.net/yangbingbinga








Swift Research 01-run Swift program with SWITFC Terminal Command compilation


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.