Xcode 编译链接问题汇总(持续更新中....)

时间:2022-01-09 09:42:41

编写程序时,经常会用到别人已经写好的模块(模块的形式不同:有些是以静态库方式提供,有些提供C语言的接口,有些提供C++的接口).所以在链接的时候经常遇到一些问题,特记录

首先要明白一个道理:

.m文件只能识别OC,C语言; 即模块是OC或C语言编写的,就一般使用.m文件就可以了.

.mm文件是针对OC,C和C++三语音的; 注意模块是C++实现的,就不能在使用.m文件,要使用.mm文件(cpp文件没用过,不知情况了)

以下是一些具体编译错误汇总:

问题1.

Xcode 编译链接问题汇总(持续更新中....)

   或者

Xcode 编译链接问题汇总(持续更新中....)

 解决方法:把.m文件修改成.mm文件

问题2

"_compress", referenced from:

“_uncompress", referenced from:

"_compress2", referenced from:

"_inflateReset", referenced from:

"_inflateInit_", referenced from:

"_inflateEnd", referenced from:

"_inflateInit2_", referenced from:

与压缩,解压缩有关的链接问题,都可以通过 -lz解决.

Xcode 编译链接问题汇总(持续更新中....)


问题3

  在音频编解码的时候,在使用G711a格式的时候,原始文件是G711.c.这个在Xcode的默认编译器中是有错误的,

解决方式:需要修改成G711.cc

问题4

Xcode 编译链接问题汇总(持续更新中....)

解决方式:添加一个libstdc++.dylib

问题5

Xcode 编译链接问题汇总(持续更新中....)

解决方式:

Xcode 编译链接问题汇总(持续更新中....)

问题5:

#ifdef ShowLog
    #define DLog(...) NSLog(__VA_ARGS__)
#else
    #define DLog(...)
#endif

///

+ (void)modifyPassword:(NSString *)password
           oldPassword:(NSString *)oldPassword
               success:(void (^)(NSDictionary *data))success
               failure:(void (^)(NSDictionary *data))failure
{
    password = [password stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    [[WebManager sharedInstance] Request:[NSString stringWithFormat:@"id=%@&password=%@&oldpassword=%@",
                                                                  @"11",
                                                                  @"11",
                                                                  @"111"]
                                                         success:success
                                                         failure:failure];
}


AFJSONRequestOperation *operation =
[AFJSONRequestOperation
 JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
     
     NSDictionary *data = (NSDictionary *)JSON;
     NSString *result = [data objectForKey:@"result"];
     
    if ([result isEqualToString:@"ok"]) {
        if (success) {
            success(data);
        }
    }
     
 }
 failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
     
 
     NSDictionary *data = [[NSDictionary alloc]
                           initWithObjects:[NSArray arrayWithObject:@"001"]
                           forKeys:[NSArray arrayWithObject:@"result"]];
     if (failure) {
         failure(data);
     }
 }];


/////


dispatch_group_t _group;
dispatch_queue_t _eventQueue;

@property (strong, nonatomic) NSMutableArray *eventObersvers;

_group = dispatch_group_create();
_eventQueue = dispatch_queue_create("com.111.eventQueue", NULL);

_eventObersvers = [[NSMutableArray alloc] init];

- (void)registerEventObserver:(id)observer {
    dispatch_group_async(_group, _eventQueue, ^{
        [self.eventObersvers addObject:observer];
    });
}
- (void)unRegisterAllEventObserver {
    dispatch_group_async(_group, _eventQueue, ^{
        [self.eventObersvers removeAllObjects];
    });
}