多个源文件的一个标头?

发布于 2025-01-05 21:38:08 字数 131 浏览 5 评论 0原文

我如何编写一个定义接口的头文件并使用单独的源文件来编写特定于平台的代码?

例如:

video.h
video_windows.c
video_linux.c
video_osx.c

How might I write a single header file that defines an interface and use a separate source files to write platform-specific code?

For example:

video.h
video_windows.c
video_linux.c
video_osx.c

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我一直都在从未离去 2025-01-12 21:38:08

在您的问题中,当您谈论源文件之间的共享标头时,您拥有所有标头文件。

无论如何,您只需提供一个通用的 .h 文件并拥有 3 个不同的文件,

video_windows.c
video_linux.c
video_osx.c

然后根据平台将正确的文件包含到您的 makefile(或您使用的任何文件)中。

如果您想直接在头文件或源文件中分离代码,您可以轻松使用一些预定义的宏,请参阅此处

In your question you have all header files while you are talking about a shared header between source files.

In any case you just provide a common .h file and have 3 different

video_windows.c
video_linux.c
video_osx.c

You then include to your makefile (or whatever you use) the correct one according to the platform.

If you want to separate code in header files or in source files directly you can easily use some predefined macros, see here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文