编译铿锵的命令行上的多个Objective-C的文件 [英] Compiling multiple Objective-C files on the command line with clang

查看:612
本文介绍了编译铿锵的命令行上的多个Objective-C的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望简单的问题。我想学习基本的Objective-C在命令行编译,铿锵。据我所知,X code是复杂的项目一个更好的解决方案,我计划很快转移到它,但我个人觉得我理解的语言更好,如果我能在终端手动编译它,并为小型编程入门项目中,我发现少了麻烦,在终端编译不必启动一个新项目。

Hopefully simple question. I'm trying to learn basic Objective-C compiling from the command line, with clang. I understand that Xcode is a better solution for complex projects and I plan on moving to it soon, but I personally feel I understand a language better if I can compile it manually in a terminal, and for small introductory programming projects I find it less of a hassle to compile in a terminal than having to start a new project.

所以现在的问题是:我怎么编译包含多个文件(命令行)一个Objective-C程序? (我试图从科昌的教材第七章做了部分程序,具有main.m文件和文件Fraction.m既#进口Fraction.h,并​​认为进口基础框架Fraction.h文件)。要编译单个文件我用类似

So the question is: how do I compile an Objective-C program that consists of multiple files (from the command line)? (I'm trying to do the fraction program from chapter 7 of Kochan's textbook, with a main.m and Fraction.m file that both #import "Fraction.h", and a Fraction.h file that imports the Foundation framework.) To compile a single file I use something like

clang -fobjc-arc main.m -o prog1

但是,如果我键入,我想包括比项目main.m文件的其他文件,我得到的错误包括:

But if I type that and I want to include files other than main.m in the project, I get errors including:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

如果我尝试将其他文件作为参数添加到命令,像

If I try to add the additional files to the command as arguments, like

clang -fobjc-arc main.m Fraction.h Fraction.m -o prog1

然后我得到

clang: error: cannot specify -o when generating multiple output files

如果我再取出参数-o像

And if I then remove the -o argument like

clang -fobjc-arc main.m Fraction.h Fraction.m

然后我得到的错误都指的是基础架构,最终在结束了一个巨大的一堆致命错误:发出太多的错误,现在停止

then I get a giant pile of errors all referring to the foundation framework, eventually ending in "fatal error: too many errors emitted, stopping now".

我如何做到这一点,并使其发挥作用?或者,我只是需要吮吸它,并尽快多个文件涉及使用X code吗?

How do I do this and make it work? Or do I need to just suck it up and use Xcode as soon as more than one file is involved?

推荐答案

只有实现文件(* .M)进行编译,而不是接口/ include文件,所以这应该工作:

Only the implementation files (*.m) are compiled, not the interface/include files, so this should work:

clang -fobjc-arc main.m Fraction.m -o prog1

生成多个输出文件奇怪的错误消息可能是由以下事实引起的
这铿锵还可以编译头文件为precompiled头文件。

The strange error message "generating multiple output files" is probably caused by the fact that clang can also compile header files to "precompiled header files".

这篇关于编译铿锵的命令行上的多个Objective-C的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆