Code for the platform

Hope to get some pointers here. I am trying to get QT to compile with slightly different code for each platform. For instance,

If the platform is Windows, then enable windows.h
If the OSX platform includes time.h

and

If the Windows platform uses the QueryPerformanceCounter function from windows.h If the Linux platform uses the gettimeofday function from time.h

The goal is to write a wrapper function to return expired microseconds that work with Windows (QueryPerformanceCounter) and Linux / Max (gettimeofday) without having 2 sets of code. Qtimer permission does not meet the requirements of Windows XP. (about 10-15 ms).

Can anyone point me to a tutorial on how to do this? Thank you in advance and Happy New Year to all.

Gary cho

+3
source share
1 answer

If it was python, I would say just create a module that conditionally imports one of the correct modules.

This is C ++, I'm sure it is not possible (I am not an expert in C ++). Even if the compiled binaries could work on both windows and Linux machines. I see no way to compile both windows and Linux headers into an executable, and then choose between them at runtime.

You will need to compile 2 binaries, each of which contains the correct header.

+1
source

Source: https://habr.com/ru/post/1783052/


All Articles