xcode dyld:找不到符号:错误如何解决此问题

zengzsys  于 2023-06-24  发布在  其他
关注(0)|答案(7)|浏览(345)

我有下面的代码(下面给出),其中我使用NSURLConnection连接和解析响应字符串。但我得到了以下错误:

dyld: Symbol not found: _CFXMLNodeGetInfoPtr
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security

我已经在这方面工作了很长一段时间,但无法修复这个错误。
我已经导入了json.h和ASIHTTPRequest.h,所有这些文件,但它还没有修复错误。

@implementation Websample1ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    dataWebService = [[NSMutableData data] retain];
    NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures&callback=handleResponse"]]retain];    

    NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
    [myConnection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{
    [dataWebService setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [dataWebService appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
    NSLog(@"Response: %@",responseString);
    [responseString release];
    [dataWebService release];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"Error during connection: %@", [error description]);
}

//class 2
@implementation WebJson
//parse JSON
- (void)requestCompleted:(ASIHTTPRequest *)request
{
    NSString *responseString = [request responseString];   
    NSDictionary *dictionary = [responseString JSONValue];
    NSDictionary *dictionaryReturn = (NSDictionary*) [dictionary objectForKey:@"request"];    
    NSString *total = (NSString*) [dictionaryReturn objectForKey:@"totalResults"];
    NSLog(@"totalResults: %@", total); 

    NSString *search = (NSString*) [dictionaryReturn objectForKey:@"searchTerms"];
    NSLog(@"searchTerms: %@", search);       

    int count = [[dictionaryReturn objectForKey:@"count"] intValue];
    NSLog(@"count: %d", count);
}
5tmbdcev

5tmbdcev1#

dyld错误是由缺少或错误的库链接引起的,而不是代码。

仔细检查你的框架链接,不要犹豫删除/重新创建链接,* 照顾 * 你的框架从iOS版本。* (通常使用Xcode提供的列表,不要浏览文件)*

在你的例子中,我不会惊讶于链接/System/Library/Frameworks/Security.framework是一个错误,因为它看起来不像属于iOS SDK,看看它的路径...
我想应该是这样的:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator<Version>.sdk/System/Library/Frameworks/Security.framework

wmtdaxz3

wmtdaxz32#

我也打了这个。原来,我不小心选中了框复制框架到我的本地目录时,添加框架到我的项目。
从项目中删除框架。
然后添加框架,确保不复制文件。

hgc7kmma

hgc7kmma3#

当您引用的库、变量或方法未在当前目标操作系统中编译时,也会发生这种情况。
因此,检查符号,看看它是否可用。例如,CFRelease(CFTypeRef cf)在所有iOS框架中都可用,但CFAutorelease(CFTypeRef arg)仅在iOS 7.0(和Mac OSX 10.9)及更高版本(由CF_AVAILABLE(10_9, 7_0)指定)中可用

bvjxkvbb

bvjxkvbb4#

当我将可执行文件加载框架时使用的后缀从'no'后缀改为'debug'后缀时,我也得到了同样的错误。我认为调试框架没有被苹果保持最新。
如果您出于其他原因使用'debug',那么您可能会遇到这种情况,然后添加一个调试版本不是最新的框架。
在XCode 3中,后缀设置可以在可执行文件的“获取信息”窗口的“常规”窗格中找到。

46scxncf

46scxncf5#

我也遇到过这个问题,这似乎是iOS 8 SDK中CFNetwork中的一个已知bug(看这里:https://devforums.apple.com/message/971238#971238).
周围的工作如下:
在目标的“Link Binary With Libraries”中更改链接顺序,将Foundation.framework放在CFNetwork.framework之前。
这为我解决了问题。

baubqpgj

baubqpgj6#

我在Mac上构建sentry本机SDK时遇到了类似的问题。

Dyld Error Message:
  Symbol not found: __ZNKSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEE3strEv
  Referenced from: /private/var/folders/*/ClassIn-LMS.app/Contents/MacOS/../Library/libsentry.dylib (which was built for Mac OS X 12.3)
  Expected in: /usr/lib/libc++.1.dylib

这是一个Deployment Target不匹配的问题。我在MacOs12.5上构建它,默认情况下Deployment TargetMacOs12.3。而app使用的是在MacOs11.4上运行的这个库。所以它崩溃了,抱怨上面的消息。
通过将Deployment Target设置为正确的版本来使其工作。
关于更改Deployment Target,您可以通过修改XcodeGeneral选项卡中的Deployment target字段来更改。或者在生成Xcode项目之前设置MACOSX_DEPLOYMENT_TARGET=10.12env。建议采用后一种。

mcvgt66p

mcvgt66p7#

将部署目标更改为iOS 8.1。

相关问题