在Linux中锵块? [英] Clang block in Linux?
本文介绍了在Linux中锵块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
锵有一个非常酷的扩展名为块带来真正的lambda函数机制C.比起块,gcc的嵌套函数相当有限。但是,试图编译一个简单的程序 C.C
:
Clang has a very cool extension named block bringing true lambda function mechanism to C. Compared to block, gcc's nested functions are quite limited. However, trying to compile a trivial program c.c
:
#include <stdio.h>
int main() {
void (^hello)(void) = ^(void) {
printf("Hello, block!\n");
};
hello();
return 0;
}
与铛-fblocks C.C
,我得到了
/usr/bin/ld.gold: /tmp/cc-NZ7tqa.o: in function __block_literal_global:c.c(.rodata+0x10): error: undefined reference to '_NSConcreteGlobalBlock'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
看来我应该使用铛-fblocks C.C -lBlocksRuntime
,但后来我得到了
/usr/bin/ld.gold: error: cannot find -lBlocksRuntime
(the rest is the same as above)
任何提示?
推荐答案
在Ubuntu Linux操作系统:
On Ubuntu Linux:
sudo apt-get install llvm
sudo apt-get install clang
sudo apt-get install libblocksruntime-dev
test.c以
:
#include <stdio.h>
int main() {
void (^hello)(void) = ^(void) {
printf("Hello, block!\n");
};
hello();
return 0;
}
编译:
clang test.c -fblocks -lBlocksRuntime -o test
./test
Hello, block!
正常工作。
这篇关于在Linux中锵块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文