Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which libraries do you need to link against for a clang program using blocks

I've discovered (below) that I need to use -fblocks when compiling code which uses blocks.

What library do I need to link against to let the linker resolve _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)
like image 395
fadedbee Avatar asked Feb 19 '10 16:02

fadedbee


People also ask

What linker does Clang use?

Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.

Does Clang include a linker?

DESCRIPTION. The clang executable is actually a small driver which controls the overall execution of other tools such as the compiler, assembler and linker.

How does Clang compiler work?

Like many other compilers design, Clang compiler has three phase: The front end that parses source code, checking it for errors, and builds a language-specific Abstract Syntax Tree (AST) to represent the input code. The optimizer: its goal is to do some optimization on the AST generated by the front end.

Should I use GCC or Clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.


1 Answers

Clang doesn't yet provide an easy way to use blocks on platforms that don't have built-in operating system support (e.g., SnowLeopard). You can find some more information on the libdispatch project here: http://libdispatch.macosforge.org/ and on the compiler-rt project (which provides the blocks runtime) here: http://compiler-rt.llvm.org/ but this is not yet well packaged for Clang end users.

If you want to dig in a bit, the compiler-rt project does have the blocks runtime in it, and you can use that to build a library which will provide the NSConcreteStackBlock.

like image 109
Daniel Dunbar Avatar answered Sep 20 '22 07:09

Daniel Dunbar