2010-02-19 20 views
5

我发现(下文)我需要在编译使用块的代码时使用-fblocks。您需要使用哪些库链接叮当程序使用块

我需要链接哪个库来让链接器解析_NSConcreteStackBlock? (在Ubuntu 9.10 AMD64)

[email protected]:~$ 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. 
[email protected]:~$ 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) 

回答

5

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

如果您想深入了解一下,编译器rt项目确实包含了块运行时,并且可以使用它来构建一个将提供NSConcreteStackBlock的库。

0

在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

相关问题