2016-11-05 61 views
9

用下面的设置(gist):雨燕 “错误:在自动导入:未能从AST方面得到模块 '富':”

Package.swift:

import PackageDescription 

let package = Package(
    name: "foo", 
    dependencies: [ 
     .Package(url: "https://github.com/rxwei/LLVM_C", majorVersion: 1, minor: 0) 
    ] 
) 

Makefile文件:

all: 
    @swift build \ 
     -Xcc -I`llvm-config --includedir` \ 
     -Xlinker -L`llvm-config --libdir` \ 
     -Xlinker -rpath -Xlinker `llvm-config --libdir` 

main.swift:

import LLVM_C.Core 

func foo(_ a: Int) { 
    let b = a * a 
    print(b) 
} 

foo(4) 

在调试器编译的可执行文件make并启动可执行文件之后,我无法打印任何变量的值:

(lldb) b foo 
Breakpoint 1: where = foo`foo.foo (Swift.Int) ->() + 12 at main.swift:4, address = 0x00000001000014dc 
(lldb) r 
Process 14376 launched: '/Users/emlai/Code/foo/.build/debug/foo' (x86_64) 
Process 14376 stopped 
* thread #1: tid = 0x226d5, 0x00000001000014dc foo`foo(a=4) ->() + 12 at main.swift:4, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 
    frame #0: 0x00000001000014dc foo`foo(a=4) ->() + 12 at main.swift:4 
    1 import LLVM_C.Core 
    2  
    3 func foo(_ a: Int) { 
-> 4  let b = a * a 
    5  print(b) 
    6 } 
    7  
(lldb) p a 
error: in auto-import: 
failed to get module 'foo' from AST context: 

(lldb) p a 
Shared Swift state for foo has developed fatal errors and is being discarded. 
REPL definitions and persistent names/types will be lost. 
warning: Swift error in module foo. 
Debug info from this module will be unavailable in the debugger. 

error: in auto-import: 
failed to get module 'foo' from AST context 

如果我注释掉import LLVM_C.Core线,一切正常。

这阻止了我调试我的项目并取得进展。我怎样才能解决这个问题?

回答

2

在网络上搜索此问题只会导致“其lldb错误”。 我发现调试的唯一方法是调试测试。但是AFAIK你不能用自己的main.swift脚本来运行测试。这导致multiple definition of 'main'

所以只要按照说明这里https://swift.org/getting-started/#using-the-package-manager创建具有试验包所需的文件层次结构(与swift package init或手动),写一些测试,运行swift test,最后lldb .build/debug/fooPackageTests.xctest<binary name>PackageTests.xctest是用于运行测试的二进制文件)。我猜想它的编译方式不同,而不是普通的二进制。至少在我的情况下工作:)

祝你好运与调试! :)