我很难在Ubuntu 16.04上安装Swift 3.0和GCD。现在这应该是可能的,对吗?
下面是一个Ansible任务,用于从swift.org下载Swift 3,克隆,构建和安装来自GitHub的swift-corelibs-libdispatch。
即使libdispatch的安装完成没有错误,它也不起作用。当我在Swift repl中尝试import Dispatch
时,它抱怨缺少功能"块"。检查Makefile确认,至少标志-fblocks
已提供给编译器。
这是Swift repl的示例输出:
vagrant@swift3:/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr/bin$ ./swift
Welcome to Swift version 3.0 (swift-3.0-PREVIEW-3). Type :help for assistance.
1> 6 * 7
$R0: Int = 42
2> import Dispatch
error: module 'CDispatch' requires feature 'blocks'
error: could not build Objective-C module 'CDispatch'
2>
用于设置框的Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.ssh.forward_agent = true
config.vm.box = "bento/ubuntu-16.04"
config.vm.define "swift3" do |dev|
dev.vm.hostname = "swift3.dev"
end
config.vm.network :private_network, ip: "10.0.0.10"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/main.yml"
end
end
安装Swift 3的Ansible任务:
---
- name: Install Swift 3 requirements
apt: name={{ item }} state=installed
with_items:
- autoconf
- clang
- git
- libblocksruntime-dev
- libbsd-dev
- libcurl4-openssl-dev
- libdispatch-dev
- libkqueue-dev
- libpython2.7-dev
- libtool
- pkg-config
- name: download Swift 3
get_url: url=https://swift.org/builds/swift-3.0-preview-3/ubuntu1510/swift-3.0-PREVIEW-3/swift-3.0-PREVIEW-3-ubuntu15.10.tar.gz
dest=/tmp/swift.tgz mode=0440
- name: unarchive Swift 3
unarchive: dest=/tmp src=/tmp/swift.tgz copy=no creates=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10
- name: clone Swift 3 libdispatch core library
git: repo=https://github.com/apple/swift-corelibs-libdispatch dest=/tmp/swift-corelibs-libdispatch
version=swift-3.0-preview-3-branch force=true
- name: generate Swift 3 libdispatch build files
command: "sh ./autogen.sh"
args:
chdir: /tmp/swift-corelibs-libdispatch
- name: configure Swift 3 libdispatch
command: "sh ./configure --with-blocks-runtime=/usr/lib/x86_64-linux-gnu --with-swift-toolchain=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr --prefix=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr"
args:
chdir: /tmp/swift-corelibs-libdispatch
- name: make Swift 3 libdispatch
command: "make"
args:
chdir: /tmp/swift-corelibs-libdispatch
- name: install Swift 3 libdispatch
command: "make install"
args:
chdir: /tmp/swift-corelibs-libdispatch
- name: grant permissions to use Swift 3
file: dest=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10 mode=a+rX recurse=true
答案 0 :(得分:2)
正如您已经注意到,编译时为libdispatch正确设置了 $(document).ready(function() {
var content, fetchAndInsert;
content = $('div#content');
// Fetches and inserts content into the container
fetchAndInsert = function(href) {
$.ajax({
url: 'http://localhost:8000/phpexample/content/' + href.split('/').pop(),
method: 'GET',
cache: false,
success: function(data) {
content.html(data);
}
});
};
// User goes back/forward
$(window).on('popstate', function() {
fetchAndInsert(location.pathname);
});
$('.buttonlink').click(function(){
var href = $(this).attr('href');
// Manipulate history
history.pushState(null, null, href);
// Fetch and insert content
fetchAndInsert(href);
return false;
});
});
链接器标志。这很好,因为现在你有一个工作版本的libdispatch。
不幸的是,你包含-fblocks
的任何内容 也需要Dispatch
链接器标记。
tl; dr解决方案是在编译时简单地向-fblocks
提供-Xcc -fblocks
。
这就是我所说的解决方法。提出了长期解决方案"ClangImporter: enable -fblocks on non-Darwin platforms"。在此之前,虽然上述解决方案是从您到达目的地的最短距离。
我自己添加,我只是使用上面的pull请求中的补丁来修补我的本地版本。 YMMV。