带有 Xcode 的 iOS 链接器标志

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21478119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:36:32  来源:igfitidea点击:

Linker flags for iOS with Xcode

iosobjective-cxcodelinkerllvm

提问by auspicious99

Where can I find documentation on the compiler flags and linker flags that we can specify for our iOS projects in Xcode?

在哪里可以找到有关我们可以在 Xcode 中为 iOS 项目指定的编译器标志和链接器标志的文档?

The present reason I want to read more on the possible flags in the first place is that the Google Admob SDK says we MUST set the linker -Objc flag, whereas Facebook SDK suggests NOT setting it for smaller binaries. So, I was wondering, can we set Objc for a particular library (google admob in this case) and have it unset for another library (facebook)? I expected to be able to find a man page or some other doc about what the compiler and linker options are in the first place, and then zoom in on Objc. There's tons of documentation and stackoverflow posts etc. on how to set linker flags in Xcode. What's lacking is a listing of possible linker flags we can set, and what they each mean.

我想首先阅读更多关于可能标志的当前原因是 Google Admob SDK 说我们必须设置链接器 -Objc 标志,而 Facebook SDK 建议不要为较小的二进制文件设置它。所以,我想知道,我们可以为特定的库(在这种情况下为 google admob)设置 Objc 并为另一个库(facebook)取消设置吗?我希望能够首先找到有关编译器和链接器选项是什么的手册页或其他文档,然后放大 Objc。有大量关于如何在 Xcode 中设置链接器标志的文档和 stackoverflow 帖子等。缺少的是我们可以设置的可能链接器标志的列表,以及它们各自的含义。

Surprisingly, googling around made me quite confused, as there's stuff on clang, llvm, llvm-gcc, etc., and LLVM sitelists a number of llvm commands but I don't see -Objc listed in any of the corresponding pages. Apart from the question of whether the compiler and linker are clang or llvm, or whatever they're called, is there a place we could go to in order to read documentation on whatever Xcode is currently using by default for compiling and linking iOS projects? (say, both Xcode 4.6 and Xcode 5.0.2, in case there are different doc sets?) Thanks!

令人惊讶的是,谷歌搜索让我很困惑,因为在 clang、llvm、llvm-gcc 等上有一些东西,而且LLVM 站点列出了许多 llvm 命令,但我没有看到 -Objc 列在任何相应的页面中。除了编译器和链接器是 clang 还是 llvm 或它们叫什么的问题之外,还有什么地方可以让我们阅读有关 Xcode 当前默认用于编译和链接 iOS 项目的文档?(比如说,Xcode 4.6 和 Xcode 5.0.2,以防万一有不同的文档集?)谢谢!

回答by Ivan Genchev

You can try man 1 ld. For the -ObjCflag in particular the description is:

你可以试试man 1 ld-ObjC特别是对于标志的描述是:

-ObjC Loads all members of static archive libraries that implement an Objective-C class or category.

-ObjC 加载实现 Objective-C 类或类别的静态存档库的所有成员。

EDIT

编辑

For your other question about the AdMob SDK and the Facebook SDK, I would suggest to add the -ObjC to the linker flags and take a look at thisarticle which explains why. Basically Facebook suggests not to use it, because your executable will end up being larger due to additional object code loaded into your binary.

对于您关于 AdMob SDK 和 Facebook SDK 的其他问题,我建议将 -ObjC 添加到链接器标志并查看解释原因的这篇文章。基本上 Facebook 建议不要使用它,因为由于加载到二进制文件中的额外目标代码,您的可执行文件最终会变得更大。

回答by Leo

I had this problem when I put a function into my .hpp file.

当我将一个函数放入我的 .hpp 文件时,我遇到了这个问题。

void logError(char const* szError)
{
    ...
}

I had to add in the inline to make it work.

我必须在内联中添加才能使其工作。

inline void logError(char const* szError)
{
    ...
}

Even better don't define your functions inside your headers.

最好不要在标题中定义函数。