ios - 使用来自 clang 的 @import?

标签 ios clang

我想用终端的 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/

相关文章:

ios - 如何在 Swift 中使用 AgoraRtcEngineKit 创建 channel 和服务器 token ?

c - C 中奇怪的内存损坏

c++ - GCC 中优先队列的奇怪 shared_ptr 比较器选择

ios - 解析 : deleting object value in column using Swift

iphone - iPhone 5 View 布局协助

ios - 如何使用 AVAudioRecorder 在 iPhone 上录制音频?

ios - Swift 4 UIButton 附加在 View 上

C++11 静态断言在使用 Clang++ 的 noexcept 检查失败?

xcode - 在基本 block 的中间发现终止符

c++ - Xcode - 如何使用 "-fexhaustive-register-search"进行编译 - 链接器崩溃需要