我想用终端的 Sublime 和 clang 编写一些代码。如何将新模块 (@import) 语法与 clang 一起使用?我尝试添加 -fmodules 标志,但它没有用。启用模块后,我还可以省略 -framework Foundation 标志吗?
clang -fmodules -framework Foundation test.mm; ./a.out
小测试文件:
#import <stdio.h>
// #import <Foundation/Foundation.h>
@import Foundation;
/*
clang -fmodules -framework Foundation test.mm; ./a.out
*/
int main(int argc, char const *argv[])
{
NSString *hello = @"Hello";
printf("%s\n", "hello world");
return 0;
}
最佳答案
您的输入文件是 Objective-C++(来自 .mm 扩展名),但模块尚未准备好用于 C++。有一个单独的标志,-fcxx-modules,但即使你使用它,你也可能会失败。要使用模块,您现在必须坚持使用 C 和 Objective-C。
在 Xcode 5 的 clang 和 OS X 10.9 上,这对于 C 和 Objective-C 应该可以正常工作。
@import Foundation;
int main() {
NSString *hello = @"Hello";
NSLog(@"%@", hello);
}
⑆ clang -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
⑆ clang -fmodules main.m && ./a.out
2013-11-20 08:51:37.638 a.out[51425:507] Hello
关于ios - 使用来自 clang 的 @import?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20083224/