why <net/route.h> can be included and compiled in IOS6.1 simulator while cannot be compiled in actual iphone?

StackOverflow https://stackoverflow.com/questions/22162197

  •  19-10-2022
  •  | 
  •  

문제

I tried to include to finish a gateway fetch problem. In xcode IOS simulator compiling process, it can be included, however in real IOS machine it can't. I can only put a copy of route.h in project and it really works in real machine. But this brings another problem in simulator. It says structs such as rt_metrics,rtstat are redefined, with an information:'Definition of 'struct rt_metricx' must be imported from module 'Darwin.net.route' before it is required'. How can I do to solve this problem? This is the header files I included in my file.

#include "route.h"
//#include <net/route.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#include <string.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <net/if_dl.h>
#include "resolv.h"

올바른 솔루션이 없습니다

다른 팁

For some reason that header file only exist in the iOS Simulator SDK, but not iOS SDK.

You can put a copy of the header file in your project and conditionally include it for iOS.

--EDIT--

#if TARGET_IPHONE_SIMULATOR
#include <net/route.h>
#else
#include "route.h"
#endif

I wrestled with this forever before realizing that if you #import both headers instead you don't even need to worry about the #if guard.

#import <net/route.h>
#import "route.h"

You can find the route.h file in /usr/include/net folder in your mac. Just copy it into your xcode project. it works ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top