2016-11-05 43 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是用於運行測試的二進制文件)。我猜想它的編譯方式不同,而不是普通的二進制。至少在我的情況下工作:)

祝你好運與調試! :)