English 中文(简体)
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)
最佳回答

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.

问题回答

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

Install the 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

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





相关问题
Add a changing icon to Ubuntu Panel

What would be the most simple way of adding and changing an icon in the Ubuntu (Gnome) Panel? I m looking for something as simple as shell scripting, but I m not restricted to that. Will write a ...

Configuring kernel

After create a new system call, how to update the kernel? I tried these lines, make-kpkg clean fakeroot make-kpkg -initrd -append-to-version=-custom kernel_image kernel_headers But Ubuntu asked me ...

save Exceptions to file in python

I want to save all following Exceptions in a file. The reason why I need this is because the IDLE for python 3.1.1 in Ubuntu raises an Exception at calltipps, but close to fast, that it isn t readble. ...

How can i monitor system statistics in kubuntu using Java?

i am doing a project related to configuration and memory analyzer for kubuntu. i want to display the system statistics information like CPU usage, RAM usage and proceses etc. graphically using an ...

How to pass "--external-locking" for mysqld in Ubuntu

I would like to start my mysql server with the --external-locking option. As mysqld is run by the /etc/init.d/mysql script ubuntu (karmic), I guess that s where I should set this "--external-locking" ...

"g++" and "c++" compiler

I just found on my Ubuntu, there are two different C++ compilers: /usr/bin/g++ and /usr/bin/c++. I am not familiar with the latter, but man c++ just jumps to the manpage of gcc. I wonder what is their ...

热门标签