python软件包等效于C
我有点像C中的初学者,我想知道是否有一种像Python这样的包裹的方法:
.
├── main.py
└── pkg
├── file1.py
├── file2.py
└── __init__.py
在C中看起来如何?
我想像是:
.
├── main.c
└── pkg
├── a.c
├── a.h
├── b.c
└── b.h
这是道路吗?如果是这样,那将如何工作?我将如何使用其中的东西?
I'm kind of a beginner in c, and I would like to know if there's a way of making a package like in python, for example:
.
├── main.py
└── pkg
├── file1.py
├── file2.py
└── __init__.py
how would that look in c?
I'd imagine something like:
.
├── main.c
└── pkg
├── a.c
├── a.h
├── b.c
└── b.h
is it the way? if so how would that work? how would I use the stuff inside it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在C中没有什么像这样的确切的东西,它不在乎包装。
当您要分发“软件包”时,可以将其构建为库,交付标题文件和预编译的库(静态或动态,每个操作系统和架构,有时是每个编译器),
如果您想将一个大项目组织到包装中,只需去像您的布局一样前进 - 您的工具不会真正在乎。您将按照使用的相对路径的相对路径包括此类“软件包”的标题。编译取决于您的工具链,但通常您有一个大型项目,其中所有来源。
There is nothing like this exact thing in C, it does not care about packages.
When you want to distribute a "package" you can build it as library, delivering the header files and precompiled libraries (static or dynamic, per OS and architecture, sometimes per compiler)
If you want to organize a big project into packages, just go ahead like your layout - your tools won't really care. You'd include headers of such "packages" by relative path from where you use it. Compilation depends on your toolchain, but generally you have one big project with all the sources.
正如LittleFox所解释的那样,没有1:1的软件包翻译成C。当然,您可以在C导入其他模块(是否编写C或不编写)中编写一个模块,并提供一些感觉像包装的东西。
您可以导入OS,它将为您提供操作系统,并且可以自己导入OS。看起来像个包裹?是的。是包装吗?否。您可以从C中做同样的事情。
As LittleFox explained, there is no 1:1 translation of a package into C. Of course you can write a module in C importing other modules (written in C or not) and provide something that feels like a package.
You can import os and it will provide os.path for you and you can import os.path on your own. Looks like a package? Yes. Is it a package? No. The same you can do from C.