何时是使用静态库所需的头文件? [英] When is a header file required for using a static library?

查看:522
本文介绍了何时是使用静态库所需的头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Linux中使用C ++创建静态库,以便生成.a文件,那么我(或任何其他人)如何使用该库?例如,我的库定义了一个类。我假设仅仅提供.a文件是不够的,而且还提供一个头文件。我如何知道必须用.a文件提供什么头文件?

If I create a static library in C++ in Linux such that a ".a" file is produced, how do I (or anyone else) use the library? For example, my library defines a class. I assume that it is not sufficient merely to provide the ".a" file, but also to provide a header file. How do I know what header files must be provided with the ".a" file?

例如,我需要提供所有的头文件,我的库的代码?

For example, do I need to provide all header files that were included anywhere in the code for my library?

推荐答案

听力的技术原因是让编译器在编译代码,了解名称尺寸,以便它可以安排用户对象的布局。

The technical reason for hearers is letting the compiler, while compiling user code, to know about names and sizes, so that it can arrange the user object's layout.

为什么 private public 类的成员(注意重点: public ,这里不是关键字)

That's the reason why private member of public classes (note the the emphases: public, here, is not the keyword) must be exposed in headers.

您可以避免将暴露部分中展开的类仅显示为指针或引用,因为它们的实际实例不会留在产生用户对象本身。

You can avoid to expose classes that are layed-out in the exposed parts only as pointers or references, since their actual instance will not leave in the resulting user object itself. In that case you can declare just the name.

您必须向用户提供


  • 用户代码需要访问

  • 在用户对象的大小和组成方面有所贡献(即使没有用户的直接了解)。

这篇关于何时是使用静态库所需的头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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