我已经发现(见下文),我需要编译它使用块代码时使用-fblocks。

我需要什么库链接反对让连接器解决_NSConcreteStackBlock? (在Ubuntu 9.10 AMD64。)

chris@chris-desktop:~$ clang ctest.c 

ctest.c:3:25: error: blocks support disabled - compile with -fblocks or pick a
      deployment target that supports them
void call_a_block(void (^blockptr)(int)) {
                        ^
ctest.c:11:19: error: blocks support disabled - compile with -fblocks or pick a
      deployment target that supports them
    call_a_block( ^(int y) { 
                  ^
2 diagnostics generated.
chris@chris-desktop:~$ clang ctest.c -fblocks
/tmp/cc-4sPSeO.o: In function `main':
ctest.c:(.text+0x79): undefined reference to `_NSConcreteStackBlock'
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)
有帮助吗?

解决方案

锵还没有提供关于不具有内置的操作系统的支持(例如,雪豹)平台使用的块的简单方法。您在这里可以找到的libdispatch项目的一些详细信息:    http://libdispatch.macosforge.org/ 和编译器-RT项目(提供块的运行),在这里:    http://compiler-rt.llvm.org/ 但这尚未很好包装用于锵最终用户。

如果你想在一个位挖,编译器RT项目确实有块在它运行时,你可以用它来建立一个库,将提供NSConcreteStackBlock。

其他提示

使用在 http://mackyle.github.com/blocksruntime/ 以构建一个指令libBlocksRuntime.a库,你可以用链接。

在Ubuntu与安装libBlocksRuntime:

sudo apt-get install llvm
sudo apt-get install clang
sudo apt-get install libblocksruntime-dev

要编译,包括库和-fblocks:

clang ctest.c -fblocks -lBlocksRuntime

这也可在其他操作系统。 FreeBSD和MidnightBSD既包括铛和libBlocksRuntime.so

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top