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)
Starting from Android API level 24 (Android 7.0 Nougat) ifaddrs.h
is supported officially, so, if you target this SDK, you don't need custom implementations anymore.
If you target older version, there is ifaddrs.h
implementation made by Google, you can find it in Android source code; the most interesting one is Gingerbread implementation, because it is C++ header only one, so you don't need to add it to you project or compile as a separate library, just add it to your includes and use.
The Android Gingerbread ifaddrs.h
implementation file URL follows:
https://android.googlesource.com/platform/libcore/+/refs/heads/gingerbread-release/luni/src/main/native/ifaddrs-android.h
It depends on 2 other include files that you can find in the same repository easily. There are also other ifaddrs.h
implementations in other Android releases sources, however, they are not header only, so theirs integration requires one additional step.
I tested Gingerbread implementation with 4 devices (Android 5.0, 6.0, 7.0 and 9.0), and I didn't have any issues.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With