What libraries do you need to link against the clang program using blocks

I found (below) that I need to use -fblocks when compiling code that uses blocks.

What library do I need to link to allow the linker to enable _NSConcreteStackBlock? (On 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) 
+5
ubuntu clang llvm objective-c-blocks
source share
3 answers

Clang does not yet provide an easy way to use blocks on platforms that do not have built-in support for the operating system (for example, SnowLeopard). Here you can find additional information about the libdispatch project: http://libdispatch.macosforge.org/ and in the compiler-rt project (which provides block execution time): http://compiler-rt.llvm.org/ but this is not enough good for end users of Clang.

If you want to dig a little, the compiler-rt project has run blocks in it, and you can use it to create a library that will provide NSConcreteStackBlock.

+5
source share

Use the instructions at http://mackyle.github.com/blocksruntime/ to create the libBlocksRuntime.a library with which you can link.

+4
source share

Install libBlocksRuntime on Ubuntu with:

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

To compile, include the library and -fblocks:

 clang ctest.c -fblocks -lBlocksRuntime 

It is also available on other operating systems. FreeBSD and MidnightBSD include clang and libBlocksRuntime.so

0
source share

All Articles