0

I'm developing a game engine for Sega Dreamcast and Windows. I have implemented my own library for the Dreamcast hardware, which pretty much does the same thing as OpenGL for PC. Now, I want to merge the two builds into one project, so I don't need to dev to different project doing the exact same high level stuff.

I know you can add a preprocessing line like this: #define DREAMCAST, and then the Dreamcast headers will be included and the appropriate low level function will be called instead of OpenGL. This has been done before, but I don't know how to make that possible.

This has really nothing to do with Dreamcast, it could be Mac, Linux or whatever. I have different compilers for each platform. So when #define DREAMCAST, I want the G++ KOS compiler to include the Dreamcast-specific headers and classes. If #define DREAMCAST is not present, I want MingGW to include the Windows OpenGL headers and classes.

How can I do this?

1 Answer 1

1

For the initial problem of including different versions depending on a predefined symbol, a simple solution is available:

#if defined(DREAMCAST)
#include <my_dreamcast_header>
#else
#include <opengl_header>
#endif

This functionality should be available on just about any C or C++ compiler - and it definitely is on MinGW. You still need to invoke the correct compiler yourself of course, as there is no way to change the compiler once compilation starts.

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

2 Comments

You could write small script that chooses compilers and invokes compilation. Python or even cmake might make a good choice
Thanks man! Appreciated. Though, the functions called for both platforms will still be compiled, which will end up in a bunch of undefined reference errors?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.