macOS 开发 - 使用 route.h 报错 (Darwin.net.route)

版权声明:本文为博主原创文章,转载请附上本文链接地址。from : https://blog.csdn.net/lovechris00 https://blog.csdn.net/lovechris00/article/details/82526910


问题场景

获取gateway 会使用到 route.h

iOS 开发中一般这样引用:

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

但是做Mac 应用时,如此调用会报很多错误,比如

Use of undeclared identifier 'RTF_GATEWAY'
Use of undeclared identifier 'RTAX_MAX'

Type 'struct rt_metrics' has incompatible definitions in different translation units

Definition of 'rt_metrics' must be imported from module 'Darwin.net.route' b

解决方法:

如下步骤:
1、 删除项目中的route.h 文件;
2、如下引用 route.h

#include <net/route.h>

3、将应用 route 的C 文件,type 改为 Objective-C source

这里写图片描述

编译,通过


做的尝试

尝试1:引入 Darwin 相关框架 libdarwin, 报错:

cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib/system/libsystem_darwin.tbd.  Link against the umbrella framework 'System.framework' instead. for architecture x86_64

再次引入 libSystem,还是编译失败;


尝试2:只引入 route.h

#include "route.h"

编译失败。


猜你喜欢

转载自blog.csdn.net/lovechris00/article/details/82526910