下面是使用__block
变量的简单程序时:错误声明__block变量“为体系结构x86_64的未定义符号”
typedef void (^incrementBlock)(void);
__block int incrementMe = 0;
incrementBlock add_one = ^{
incrementMe++;
};
incrementBlock add_two = ^{
incrementMe++;
incrementMe++;
};
add_one();
add_two();
printf("%d", incrementMe);
当我编译此,我得到这个错误:
Undefined symbols for architecture x86_64: "___objc_personality_v0", referenced from: _main in test-b0a9a6.o Dwarf Exception Unwind Info (__eh_frame) in test-b0a9a6.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
它肯定是一个问题,宣布incrementMe
为__block int
,当我评论它的作品。
我试着编译与gcc,它也没有工作。
我从书中或多或少直接得到这个例子,所以它应该工作。
我的声明已弃用吗?我应该以不同的方式声明一个可变块变量吗?
“__block”不是Objective-C关键字吗?为什么这个问题标记为C++? –
https://twitter.com/tewha/status/271806872187703296可以吗? – Tommy
@RSahu 对不起,我只是学习块,所以我不知道如何标记 - 我的坏 –