Swift 现在是开源的。有人试过为 Raspberry PI 编译 Swift 吗?我开始做,但我的 8 GB SD 卡似乎太小了;)是否可以从 Ubuntu 交叉编译它?
最佳答案
8GB SD 卡可以正常工作,但您需要扩展根卷。我让它正常工作,/dev/root
分区上的已用空间约为 3.1GB。
以下步骤基于 Andrew Madsen 的博文额外关注 fdisk
中的步骤。
获取 Ubuntu
从 finnie.org 下载适用于 Raspberry Pi 2 的 Ubuntu 14.04 镜像并将其复制到 SD 卡上。启动树莓派。
更改分区
登录 Raspberry Pi 并更改分区大小。 /dev/root
的默认大小为 1.7G,其中 1.1G 可用。这还不够。
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.7G 540M 1.1G 35% /
devtmpfs 458M 4.0K 458M 1% /dev
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 93M 228K 93M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 462M 0 462M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mmcblk0p1 64M 20M 45M 31% /boot/firmware
运行磁盘
sudo fdisk /dev/mmcblk0
在提示符下输入 p
表示“打印分区表”。有两个分区
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 3670015 1768448 83 Linux
出现提示时,输入 d
(删除),然后输入 2
。然后,通过输入 n
、p
、2
重新创建分区,然后在接下来的两个提示中按 enter 接受默认值。
再次输入p
,第二个分区变大了,8GB卡上的所有空间都用完了。
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 15523839 7695360 83 Linux
输入w
将更改写入磁盘,然后重新启动
sudo reboot
调整分区大小
重启后,通过运行调整分区文件系统的大小
sudo resize2fs /dev/mmcblk0p2
交换空间
通过执行设置交换文件
sudo apt-get install dphys-swapfile
安装 libicu-dev 和 clang-3.6
sudo apt-get install libicu-dev clang-3.6
使用 update-alternatives 为 clang 和 clang++ 提供/usr/bin 链接:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
然后,添加@iachievedit 的存储库 key :
wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -
将适当的存储库添加到 sources.list:
echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list
运行 apt-get 更新:
sudo apt-get update
安装 Swift
sudo apt-get install swift-2.2
安装完成后,就可以编译Swift程序了!
编写 Swift
打开你最喜欢的文本编辑器,编写一个程序,然后保存(例如保存到“hello.swift”):
let device = "Raspberry Pi 2!"
print("Hello from Swift on \(device)")
编译
swiftc hello.swift
并运行它:
./hello
Hello from Swift on Raspberry Pi 2!
就是这样!在树莓派上运行 Swift
关于swift - (交叉)为 Raspberry PI 编译 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107889/