Search code examples
androidc++macosincludesdl

ifaddrs.h header not found when compiling SDL for android


I'm making an android game with SDL that requires access to ifaddrs.h. when I compile for mac, it works fine. When I compile for Android, it says file not found.

I'm trying to include it like this:

#include <ifaddrs.h>

So I

gcc -M network.cpp

to find dependancies to the file it's included in, so I can find ifaddrs' absolute location, which is

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/ifaddrs.h

so when I

#include "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/ifaddrs.h"

it finds it, but then errors on including some other dependency of ifaddrs

#include <AvailabilityInternal.h>

Ok. So, why is the include behavior different when I try to compile for android vs for mac? (using ndkbuild or g++ on mac)? how can I get it to work on android? what piece of knowledge/information am I missing for all this to sense?

(note- currently running OSX yosemite, 10.10)


Solution

  • You can't use MacOSX includes for Android. Different platforms, different SDKs.

    Android does not have its own native ifaddrs.h implementation (and thus does not have the getifaddrs() function). However, there is a third-party implementation available:

    https://github.com/kmackay/android-ifaddrs
    https://github.com/morristech/android-ifaddrs
    https://www.openhub.net/p/android-ifaddrs/

    An implementation of getifaddrs() for Android, since the NDK does not natively support it.

    Works just like you would expect on regular Linux.