XCode include system file instead of local file

2019-09-14 04:59发布

问题:

I am working on an iOS project and include ifaddrs.h in one of my files using

#include <ifaddrs.h>

Recently, my code stopped working (in particular, getifaddrs) and I noticed that BLWebSocketsServer delivers a getifaddrs.h/.c which seems to cause issues. If I remove those two files from XCodes "Headers" and "Compile Sources" phase, my code starts working again.

Now, for my questions:

  1. Why does this happen? getifaddrs.h is not <ifaddrs.h>, so this shouldn'at affect my code, should it?

  2. Is there a way to resolve this without altering BLWebSocketsServer?

Thanks!

回答1:

Looking at getifaddrs.[hc] in BLWebSocketsServer, they are redefining getifaddrs, so the system implementation is being overridden (and the #include is basically irrelevant)

It looks like you can work around that by defining HAVE_GETIFADDRS=1 on your compiler command lines (or in options in the Xcode project settings)

Defining HAVE_GETIFADDRS is somewhat equivalent to removing the files from the compile phase, but has the added benefit that the other sources in BLWebSocketsServer won't be using possibly invalid declarations of getifaddrs related calls and structures.