2010-02-19 63 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