Xcode 中的链接器错误?
Linker error in Xcode?
当我尝试在模拟器上 运行 我的应用程序时出现奇怪的错误。错误在以下 code/file 内。 (我不确定它叫什么):
Undefined symbols for architecture i386:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
上面的错误有两部分以红色突出显示; "_main", referenced from:
和 linker command failed with exit code 1 (use -v to see invocation)
.
我以前从未遇到过这个错误。因此,我无法修复它。这是我的代码,以备不时之需:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBOutlet weak var strWordValue: UILabel!
@IBOutlet weak var strInputField: UITextField!
func textFieldShouldReturn(textField: UITextField) -> Bool{
textField.resignFirstResponder()
let word = textField.text
let score = scoreForWord(word)
return true
}
var TextField: UITextField!
private let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
func valueOfLetter(letter: Character) -> Int
{
let letterString = String(letter).uppercaseString
let index = find(alphabet, letterString)
return index != nil ? index! + 1 : 0
}
func scoreForWord(word: String) -> Int
{
let characters = Array(word)
return characters.reduce(0) { sum, letter in sum + self.valueOfLetter(letter) }
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
let currentWord = textField.text as NSString
let newWord = currentWord.stringByReplacingCharactersInRange(range, withString: string)
let score = scoreForWord(newWord)
return true
}
}
请解释此错误的含义。
这意味着实现您的 main() 函数的文件没有链接到您的可执行文件中。
这个错误信息几个月前就发生在我身上了。模拟器不支持您的库。您需要 运行 在实际设备上而不是模拟器上。
当我尝试在模拟器上 运行 我的应用程序时出现奇怪的错误。错误在以下 code/file 内。 (我不确定它叫什么):
Undefined symbols for architecture i386:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
上面的错误有两部分以红色突出显示; "_main", referenced from:
和 linker command failed with exit code 1 (use -v to see invocation)
.
我以前从未遇到过这个错误。因此,我无法修复它。这是我的代码,以备不时之需:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBOutlet weak var strWordValue: UILabel!
@IBOutlet weak var strInputField: UITextField!
func textFieldShouldReturn(textField: UITextField) -> Bool{
textField.resignFirstResponder()
let word = textField.text
let score = scoreForWord(word)
return true
}
var TextField: UITextField!
private let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
func valueOfLetter(letter: Character) -> Int
{
let letterString = String(letter).uppercaseString
let index = find(alphabet, letterString)
return index != nil ? index! + 1 : 0
}
func scoreForWord(word: String) -> Int
{
let characters = Array(word)
return characters.reduce(0) { sum, letter in sum + self.valueOfLetter(letter) }
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
{
let currentWord = textField.text as NSString
let newWord = currentWord.stringByReplacingCharactersInRange(range, withString: string)
let score = scoreForWord(newWord)
return true
}
}
请解释此错误的含义。
这意味着实现您的 main() 函数的文件没有链接到您的可执行文件中。
这个错误信息几个月前就发生在我身上了。模拟器不支持您的库。您需要 运行 在实际设备上而不是模拟器上。