你需要使用哪些库来链接叮当声程序

我发现(下面),当编译使用块的代码时,我需要使用-fblocks。

我需要链接哪个库来让链接器parsing_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) 

铿锵还没有提供一个简单的方法来在没有内置操作系统支持的平台上使用块(例如,SnowLeopard)。 您可以在这里找到更多有关libdispatch项目的信息: http ://libdispatch.macosforge.org/和compiler-rt项目(它提供了块运行时): http : //compiler-rt.llvm.org/但是这对Clang最终用户来说还不是很好的包装。

如果你想深入了解一下,编译器rt项目里面有块运行时,你可以用它来建立一个库,它将提供NSConcreteStackBlock。

在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都包括clang和libBlocksRuntime.so