gpt4 book ai didi

ios - 为 iOS7 编译 libnet 1.1.7 时遇到问题

转载 作者:行者123 更新时间:2023-11-29 02:43:06 25 4
gpt4 key购买 nike

我正在尝试在 iOS 项目中使用 libnet 1.1.7,但出现了一些错误:

Ld /Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Products/Debug-iphonesimulator/net_tools.app/net_tools normal i386
cd /Users/admin/Desktop/net_tools
setenv IPHONEOS_DEPLOYMENT_TARGET 7.0
setenv PATH "/Applications/Разработка/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Разработка/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Разработка/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Разработка/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Products/Debug-iphonesimulator -L/usr/local/lib -F/Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Products/Debug-iphonesimulator -filelist /Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Intermediates/net_tools.build/Debug-iphonesimulator/net_tools.build/Objects-normal/i386/net_tools.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -lnet -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.0 -framework CoreGraphics -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Intermediates/net_tools.build/Debug-iphonesimulator/net_tools.build/Objects-normal/i386/net_tools_dependency_info.dat -o /Users/admin/Library/Developer/Xcode/DerivedData/net_tools-gnkjrfjgtxkpesepyzzpunpfdwkx/Build/Products/Debug-

ld: warning: ignoring file /usr/local/lib/libnet.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libnet.dylib
Undefined symbols for architecture i386:
"_libnet_addr2name4", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
"_libnet_addr2name6_r", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
"_libnet_destroy", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
"_libnet_init", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
"_libnet_name2addr4", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
"_libnet_name2addr6", referenced from:
-[AppDelegate application:didFinishLaunchingWithOptions:] in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是我在 AppDelegate.m 中的简单代码:

#import "AppDelegate.h"
#import <libnet.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

libnet_t *lnet;
char errbuf[LIBNET_ERRBUF_SIZE];
u_int32_t addr;
struct libnet_in6_addr addr6;
char ipv6addr[64];
char addr_str[] = "www.google.com";
lnet = libnet_init(LIBNET_RAW4, NULL, errbuf);
if ( lnet == NULL ) {
NSLog(@"libnet_init() failed: %s", errbuf);
exit(EXIT_FAILURE);
}
//IPv4
addr = libnet_name2addr4(lnet, addr_str, LIBNET_RESOLVE);
NSLog(@"%s",libnet_addr2name4(addr, LIBNET_DONT_RESOLVE));
//IPv6
addr6 = libnet_name2addr6(lnet, addr_str, LIBNET_RESOLVE);
libnet_addr2name6_r(addr6, LIBNET_DONT_RESOLVE, ipv6addr,
sizeof(ipv6addr));
NSLog(@"%s",ipv6addr);
libnet_destroy(lnet);

return YES;
}
@end

谁能详细解释一下这个错误,以及如何纠正它?任何帮助将不胜感激。

附言我在 Mavericks (v10.9.4) 上使用 Xcode 5.0.1

更新。我已经从源代码为 i386 arch 重建了 libnet,但只有一个错误:

ld: building for iOS Simulator, but linking against dylib built for MacOSX file '/usr/local/lib/libnet.dylib' for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我认为从 iOS 的源代码编译 libnet 存在问题。如何正确操作?

最佳答案

Get libnet 1.1.7

打开终端窗口并转到 libnet 文件夹,接下来我们需要为 iOS7 模拟器编译 libnet:

export CC=clang
export IPHONEOS_DEPLOYMENT_TARGET=7.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"
export CFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -mios-simulator-version-min=7.0"
./configure
make
sudo make install

首先在 Xcode 中选择项目。选择目标,然后选择build设置。在 Build Settings 中向下滚动,直到您到达 Linking 部分。在 Other Linker Flags 选项下,添加 -lnet。现在向下滚动,直到到达搜索路径部分并将/usr/local/lib 添加到库搜索路径。最后,将/usr/local/include 添加到 header 的搜索路径中。

关于ios - 为 iOS7 编译 libnet 1.1.7 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25507153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com