Question

This is my first blog or question. I want to develop platform abstract layer(PLA) for mobile app using c++. i.e from mobile app I could able to talk to bluetooth device without bothering which is underlying OS (i.e IOS ANDROID etc) running. So, I need to discover which OS is running whether IOS or ANDROID using c++ code but without calling native API of any OS.

  1. So, could anybody suggest your thought for the same how we can determine the OS type (ie, IOS, ANDROID) and OS version using c++ code.

  2. To develop which IDE would be preferred to develop c++ code?

Thanks in advance..!!

Thanks, Raju.

Was it helpful?

Solution

Even if you're developing cross platform code, when the time to compile it comes, you need to target a platform. Determining it is then a matter of checking precompiler definitions.

Most compiler will define some platform while compiling, if not, you can do so by yourself when configuring your project.

For example, Xcode will define __APPLE__ and TARGET_OS_IPHONE and TARGET_OS_MAC when compiling respectively iOS and Mac projects.

For Android, __ANDROID__ should be defined by the toolchain however I've seen multiple mk files add explicit platform flags like so:

LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS)

It is then a matter of using precompilation conditions:

#ifdef __APPLE__
    #if TARGET_OS_IPHONE
        // Configure for iPhone
    #endif
#endif

#ifdef ANDROID
    // Configure for Android
#endif

For determining the version, there isn't really anyway to do that without calling Native API. Fortunately, there is pattern you can use to factor out the specific implementation and put a generic interface in front of this code.



As far as IDE, this is largely a matter of choice and availability. Most popular ones are Xcode for iOS and Eclipse for Android but it is possible to use other as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top