I am trying to write a few functions that work when compiling for windows AND linux, and I can't seem to find the linux equivilent of a few windows functions. If it's of any relavance I intend to use GCC to compile for linux and VC++ to compile for Windows.

These are the windows functions that I can't find an equivinent to:
IsDebuggerPresent
GetCommandLine
QueryPerformanceCounter & QueryPerformanceCount

The answer is:
- I don't know.
- Boost.Program-options
- Boost.Date-time

Let me elaborate:

For the first problem, "IsDebuggerPresent", it is the first time I hear of such a function, I have no idea if it has or can have an equivalent in Linux. As far as I know, you do either debug builds or release builds, so there is no need for a run-time check for a debugger being possibly present. I might be wrong.

For the second problem, "GetCommandLine", I would recommend you switch entirely to Boost.Program-options for both Linux and Windows. This is a cross-platform library that will allow you to create a global object that captures, parses, and holds all data from the command-line (as you specify the possible user-inputs and capture the command-line input at the start of main()). This will be better in either cases, windows or linux.

For the third problem, I would recommend you use Boost.Date-time. Again, this is a cross-platform library which is implemented such that it takes the most precise timer available on the current platform. Basically, you ask for local_time in microseconds or nanoseconds and you will get it to the best possible precision available. You should probably switch entirely to that library for both OSes also.

As a final note, when porting code between OSes, you definitely want to take an approach like that of Boost. This means, you should wrap all the OS-specific in compact library that isolates it from the rest of the code, then, the rest of the code only makes use of that OS-agnostic (or cross-platform) library.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.