多个源文件的一个标头?
我如何编写一个定义接口的头文件并使用单独的源文件来编写特定于平台的代码?
例如:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的问题中,当您谈论源文件之间的共享标头时,您拥有所有标头文件。
无论如何,您只需提供一个通用的
.h
文件并拥有 3 个不同的文件,然后根据平台将正确的文件包含到您的 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 differentYou 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.