简体   繁体   English

import =动态链接? &include =静态链接?

[英]import = dynamic linking? & include = static linking?

I wonder the difference of import and include in Object-c 我想知道导入和包含在Object-c中的区别

By the way, I am not clear about the difference of dynamic and static linking. 顺便说一句,我不清楚动态和静态链接的区别。

If I use a library with static linking, is that mean I copy the code i need from library for my program and link with them? 如果我使用带有静态链接的库,这是否意味着我需要从库中为我的程序复制我需要的代码并与它们链接? Then my program can work with the code from library. 然后我的程序可以使用库中的代码。

If i use a library with dynamic linking, is that mean I only reference the code i need from library to my program when my program is running. 如果我使用带动态链接的库,那就意味着我只在程序运行时将我需要的代码从库引用到我的程序中。 Then my program can work with the "reference code". 然后我的程序可以使用“参考代码”。

#import vs. #include and static vs. dynamic linking are two completely unrelated topics. #import vs. #include和静态与动态链接是两个完全不相关的主题。

#include includes the contents of a file directly in another file, and is available in C (and therefore also in Objective-C). #include直接在另一个文件中包含文件的内容,并且在C中可用(因此也在Objective-C中)。 However, it's common to want to include the contents of a file only if that file hasn't already been included . 但是, 只有在 尚未包含该文件的情况下希望包含文件的内容。 (You don't, for example, want to declare the same variables twice; it'd cause compiler errors!) That's why #import was added in Objective-C; (例如,您不希望两次声明相同的变量;它会导致编译器错误!)这就是为什么在Objective-C中添加#import的原因; it does exactly that: includes the contents of a file only if that file hasn't already been #import ed. 它完全是这样的: 只有当文件尚未被#import编辑时才包含文件的内容。 If you're not sure what to use, you should probably be using #import . 如果你不确定要使用什么,你可能应该使用#import

Static vs. dynamic linking is completely different--linking happens after compilation, so it couldn't possibly be related to #import and #include , which are part of the source code. 静态与动态链接完全不同 - 链接编译之后发生,因此它不可能与#import#include相关,它们是源代码的一部分。 Your thoughts on linking are exactly correct, however--statically linked libraries are included in your app, and your users don't need them. 您对链接的想法完全正确,但是 - 您的应用中包含静态链接的库,您的用户不需要它们。 Dynamically linked libraries are referenced, and must be present on your users' machines for your app to run. 引用了动态链接库,并且必须存在于用户的计算机上才能运行应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM