Kotlin/Native 개발 환경 구축 및 설치 절차 및 자습서
                                            
                                                
                                                
                                                
                                                
                                                
                                                 8582 단어  컴파일러KotlinNative리눅스macosKotlin
                    
소개
 Kotlin/Native 의 macOS/Linux용 빌드 환경(※빌드 툴의 Gradle 없음)의 인스톨 순서를 정리하고 있습니다. 다만, 2020/1월 시점에서 Kotlin/Native 자체가 아직 베타판이라고 하는 상황입니다.
 전제
Kotlin 소스 코드를 컴파일하는 데 JDK (Java 환경)가 필요하므로 사전에 설치해야합니다.
 Kotlin/Native 설치
 htps : // 기주 b. 코 m / ぇ tB 라이언 s / 코 t ぃ / ぇ 아세 s / ㅁ st
에 있는 정식 릴리스 최신판을 이용합니다.
여기에서는 다운로드에 wget 명령을 이용하기 때문에, 미설치의 분은 필요에 따라서 인스톨 해 주세요.
 사전 준비
 macOS
$ brew install wget
 Linux(Ubuntu)
$ sudo apt install wget
 컴파일러 다운로드
 macOS
$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-macos-1.3.61.tar.gz
 Linux(Ubuntu)
$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-linux-1.3.61.tar.gz
 컴파일러 설치
 macOS/Linux 공통
적절한 위치에 압축을 풀고 환경 변수 경로를 통해 둡니다. 여기에서는/usr/local/kotlin-native에 배치하기로 하겠습니다.
$ tar xzvf kotlin-native-macos-1.3.61.tar.gz
$ sudo mkdir -p /usr/local/kotlin-native
$ sudo mv kotlin-native-macos-1.3.61/* /usr/local/kotlin-native
컴파일러 바이너리에 대한 경로를 통과시키기 위해 ~/.bash_profile에 경로를 추가합니다.
~/.bash_profile$ export PATH=$PATH:/usr/local/kotlin-native/bin/
 [선택 사항] IntelliJ IDEA 설치
Gradle을 사용하지 않는 경우 추가로 필요한 패키지(예: Coroutines라면 kotlinx:kotlinx-coroutines-core-native 등)를 직접 찾아와 명령줄 옵션으로 지정해야 합니다. 이 경우 문제는 어디에서 다운로드해야할지 모르겠다는 것입니다. 그 때문에, IntelliJ IDEA는 인스톨 해 두어, Gradle 환경도 사용할 수 있도록 해 두는 것이 편리합니다…
 여기 에서 다운로드합니다. macOS 환경의 경우 dmg 파일이므로 GUI 작업으로 설치합니다. 한편 리눅스 환경의 경우는 적당한 장소에 압축을 풀고 패스를 통과시키는 것만으로 사용할 수 있습니다.
 
덧붙여 Kotlin 플러그인은 이미 인스톨 끝난 상태가 되어 있다고 생각하므로, 이대로 프로젝트 신규 작성으로 사용할 수 있습니다.
 동작 확인용 소스 코드
hello.ktfun main(args: Array<String>) {
    println("Hello, World!")
}
 컴파일
처음 실행할 때 LLVM과 같은 종속 패키지를 다운로드하고 설치하는 데 시간이 걸립니다.
$ kotlinc-native hello.kt -o hello
또한 -D 옵션으로 Java 옵션을 전달할 수 있으므로 네트워크 환경에서 프록시 설정이 필요한 분은 다음과 같이 실행하십시오.
정보 참조원은 여기 입니다.
$ kotlinc-native hello.kt -o hello ¥
     -Dhttp.proxyHost=hoge.host.co.jp -Dhttp.proxyPort=12345 ¥
     -Dhttps.proxyHost=hoge.host.co.jp -Dhttps.proxyPort=12345
 실행
$ ./hello.kexe
Hello, World!
macOS/Linux의 네이티브 환경에서 Kotlin 프로그램을 실행할 수 있었습니다!
 라이브러리 생성
-p 옵션을 이용하는 것으로 몇개의 형식의 라이브러리화가 가능해, 헤더 파일도 자동 생성해 줍니다.
iOS/macOS의 framework에도 대응하고 있어 상당히 잘 되어 있습니다만, dynamic 지정시의 C/C++용의 헤더 파일은 상당히 좋지 않은 생각이 듭니다… 좀 더 괜찮은 매크로를 원해 ...
$ kotlinc-native hello.kt -p dynamic
선택적 인수
내용
program
일반 실행 바이너리
static
.a 파일
dynamic
Linux 환경이면 .so, macOS이면 .dylib
framework
iOS/macOS용 프레임워크 형식
library
klib (Kotlin 라이브러리 형식)
bitcode
bc 파일 (LLVM의 Bitcodebc)
사용법을 모르는 경우 -h 옵션으로 도움말 메시지를 확인할 수 있습니다.
$ kotlinc-native -h
Usage: kotlinc-native <options> <source files>
where possible options include:
  -g                         Enable emitting debug information
  -enable-assertions (-ea)   Enable runtime assertions in generated code
  -friend-modules <path>     Paths to friend modules
  -generate-no-exit-test-runner (-trn)
                             Produce a runner for unit tests not forcing exit
  -generate-test-runner (-tr) Produce a runner for unit tests
  -generate-worker-test-runner (-trw)
                             Produce a worker runner for unit tests
  -include-binary (-ib) <path> Pack external binary within the klib
  -library (-l) <path>       Link with the library
  -library-version (-lv) <version>
                             Set library version
  -linker-options <arg>      Pass arguments to linker
  -list-targets              List available hardware targets
  -entry (-e) <name>         Qualified entry point name
  -manifest <path>           Provide a maniferst addend file
  -memory-model <model>      Memory model to use, 'strict' and 'relaxed' are currently supported
  -module-name <name>        Specify a name for the compilation module
  -native-library (-nl) <path> Include the native bitcode library
  -no-default-libs           Don't link the libraries from dist/klib automatically
  -no-endorsed-libs          Don't link the endorsed libraries from dist automatically
  -nomain                    Assume 'main' entry point to be provided by external libraries
  -nopack                    Don't pack the library into a klib file
  -nostdlib                  Don't link with stdlib
  -opt                       Enable optimizations during compilation
  -output (-o) <name>        Output name
  -produce (-p) {program|static|dynamic|framework|library|bitcode}
                             Specify output file kind
  -repo (-r) <path>          Library search path
  -linker-option <arg>       Pass argument to linker
  -target <target>           Set hardware target
  -Werror                    Report an error if there are any warnings
  -api-version <version>     Allow to use declarations only from the specified version of bundled libraries
  -X                         Print a synopsis of advanced options
  -help (-h)                 Print a synopsis of standard options
  -kotlin-home <path>        Path to Kotlin compiler home directory, used for runtime libraries discovery
  -language-version <version> Provide source compatibility with specified language version
  -P plugin:<pluginId>:<optionName>=<value>
                             Pass an option to a plugin
  -progressive               Enable progressive compiler mode.
                             In this mode, deprecations and bug fixes for unstable code take effect immediately,
                             instead of going through a graceful migration cycle.
                             Code written in the progressive mode is backward compatible; however, code written in
                             non-progressive mode may cause compilation errors in the progressive mode.
  -nowarn                    Generate no warnings
  -verbose                   Enable verbose logging output
  -version                   Display compiler version
  @<argfile>                 Read compiler arguments and file paths from the given file
 사용해 본 소감
사용해 본 감상으로서는, 보통으로 움직이지만 어쨌든 빌드가 느리네요… Kotlin 1.4에서 컴파일러가 새로워짐 그렇기 때문에, 그것에 기대입니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Kotlin/Native 개발 환경 구축 및 설치 절차 및 자습서), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/kurun_pan/items/7c37a92ecbd037dfda6f
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
$ brew install wget
$ sudo apt install wget
$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-macos-1.3.61.tar.gz
$ wget https://github.com/JetBrains/kotlin/releases/download/v1.3.61/kotlin-native-linux-1.3.61.tar.gz
$ tar xzvf kotlin-native-macos-1.3.61.tar.gz
$ sudo mkdir -p /usr/local/kotlin-native
$ sudo mv kotlin-native-macos-1.3.61/* /usr/local/kotlin-native
$ export PATH=$PATH:/usr/local/kotlin-native/bin/
fun main(args: Array<String>) {
    println("Hello, World!")
}
$ kotlinc-native hello.kt -o hello
$ kotlinc-native hello.kt -o hello ¥
     -Dhttp.proxyHost=hoge.host.co.jp -Dhttp.proxyPort=12345 ¥
     -Dhttps.proxyHost=hoge.host.co.jp -Dhttps.proxyPort=12345
$ ./hello.kexe
Hello, World!
$ kotlinc-native hello.kt -p dynamic
$ kotlinc-native -h
Usage: kotlinc-native <options> <source files>
where possible options include:
  -g                         Enable emitting debug information
  -enable-assertions (-ea)   Enable runtime assertions in generated code
  -friend-modules <path>     Paths to friend modules
  -generate-no-exit-test-runner (-trn)
                             Produce a runner for unit tests not forcing exit
  -generate-test-runner (-tr) Produce a runner for unit tests
  -generate-worker-test-runner (-trw)
                             Produce a worker runner for unit tests
  -include-binary (-ib) <path> Pack external binary within the klib
  -library (-l) <path>       Link with the library
  -library-version (-lv) <version>
                             Set library version
  -linker-options <arg>      Pass arguments to linker
  -list-targets              List available hardware targets
  -entry (-e) <name>         Qualified entry point name
  -manifest <path>           Provide a maniferst addend file
  -memory-model <model>      Memory model to use, 'strict' and 'relaxed' are currently supported
  -module-name <name>        Specify a name for the compilation module
  -native-library (-nl) <path> Include the native bitcode library
  -no-default-libs           Don't link the libraries from dist/klib automatically
  -no-endorsed-libs          Don't link the endorsed libraries from dist automatically
  -nomain                    Assume 'main' entry point to be provided by external libraries
  -nopack                    Don't pack the library into a klib file
  -nostdlib                  Don't link with stdlib
  -opt                       Enable optimizations during compilation
  -output (-o) <name>        Output name
  -produce (-p) {program|static|dynamic|framework|library|bitcode}
                             Specify output file kind
  -repo (-r) <path>          Library search path
  -linker-option <arg>       Pass argument to linker
  -target <target>           Set hardware target
  -Werror                    Report an error if there are any warnings
  -api-version <version>     Allow to use declarations only from the specified version of bundled libraries
  -X                         Print a synopsis of advanced options
  -help (-h)                 Print a synopsis of standard options
  -kotlin-home <path>        Path to Kotlin compiler home directory, used for runtime libraries discovery
  -language-version <version> Provide source compatibility with specified language version
  -P plugin:<pluginId>:<optionName>=<value>
                             Pass an option to a plugin
  -progressive               Enable progressive compiler mode.
                             In this mode, deprecations and bug fixes for unstable code take effect immediately,
                             instead of going through a graceful migration cycle.
                             Code written in the progressive mode is backward compatible; however, code written in
                             non-progressive mode may cause compilation errors in the progressive mode.
  -nowarn                    Generate no warnings
  -verbose                   Enable verbose logging output
  -version                   Display compiler version
  @<argfile>                 Read compiler arguments and file paths from the given file
Reference
이 문제에 관하여(Kotlin/Native 개발 환경 구축 및 설치 절차 및 자습서), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kurun_pan/items/7c37a92ecbd037dfda6f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)