2012-03-19 51 views
5

我正在嘗試在動態鏈接的球拍中創建一個可執行文件。目前我的hello world程序編譯爲4MB可執行文件。那就是:如何在Racket中創建動態鏈接的可執行文件?

#!/usr/bin/env racket 
#lang racket 

(define (extract str) 
    (substring str 4 7)) 

(print (extract "the cat out of the bag")) 

我使用

拉科EXE first.rkt

而生成的可執行文件是4+ MB編譯它。顯然,它是靜態鏈接球拍庫。

- 編輯---

這裏是啓動代碼:

#lang racket 

(require launcher/launcher) 
(require racket/runtime-path) 

(define-runtime-path prog-path "first.rkt") 

(make-racket-launcher (list (path->string prog-path)) 
         "first" 
         '()) 

它只需要放在一個單獨的文件,並執行

racket <launch-file>.rkt 

回答

7

raco exe輸出是指靜態包括其所需的模塊,所以它可能不是你想要的。你看過launcher庫嗎?它會創建一個exe文件,只包含絕對最低限度的啓動程序在本地安裝。

或者,選擇一種較小的語言,如#lang racket/base,由於它不鏈接到儘可能多的模塊,應該生成較小的可執行文件。

最後,如果你在一個基於Unix的系統上,如果它的可執行位(x)已被設置,程序應該已經作爲一個可執行文件,因爲你已經在頂部添加了#!/usr/bin/env球拍線。這假定你的球拍處於PATH狀態。請參閱http://docs.racket-lang.org/guide/scripts.html

+0

謝謝。有效!! :) – Salil 2012-03-19 22:14:09

相關問題