Gary
Gary

Reputation: 99

Platform specific code

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

If platform is Windows then include windows.h
If platform is OSX then include time.h

AND

If platform is Windows use QueryPerformanceCounter function from windows.h If platform is Linux use gettimeofdayfunction from time.h

The objective here is to write wrapper function to return elapsed microseconds that works with Windows (QueryPerformanceCounter) & Linux/Max (gettimeofday) without having 2 sets of code. Qtimer resolution is inadequate in Windows XP. (about 10-15ms increments).

Anyone can point me to a tutorial on how to do this ? Thank you in advance and Happy New Year to everyone here.

Gary Cho

Upvotes: 3

Views: 1213

Answers (1)

Falmarri
Falmarri

Reputation: 48587

If this was python, I'd say just create a module that conditionally imports one of the correct modules.

This being C++, I'm fairly certain this isn't possible (I'm not a C++ expert). Even if the compiled binaries were able to run on both windows and linux machines. I don't see any way to compile both windows and linux headers into an executable and then choose between them at runtime.

You're going to need to compile 2 binaries that each include the correct header.

Upvotes: 1

Related Questions