I did it the following way:
main.cpp and api.h does not suffer any modification.
api.cpp:
#ifdef linux
#include "linux_api.h"
#endif
#ifdef WIN32
#include "windows_api.h"
#endif
void helloWorld() {
#ifdef linux
helloWorld_linux();
#endif
#ifdef WIN32
helloWorld_win32();
#endif
}
Then you need to provide linux_api.h
, linux_api.cpp
and windows_api.h
, windows_api.cpp
. The advantage is that this four files are already platform specific. You only have to create the "glue code" in api.cpp
for each function.
linux_api.h:
void helloWorld_linux();
linux_api.cpp:
#include "linux_api.h"
#include <cstdio>
void helloWorld_linux()
{
std::printf( "Hello world from linux..." );
}
Hope this helps.