4

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

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Are you saying that the header file only has to match the object file in name? i.e. a.h matches a.o?
The name of the header is not related to the name of the source file. You can call it foo.h and then define its methods in a file called bar.c without any kind of problem. You just #include "foo.h" in source file and in all the others involved.. there are no restrictions or constraints to keep with header file names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.