1. 程式人生 > >Xcode 編譯連結問題彙總(持續更新中....)

Xcode 編譯連結問題彙總(持續更新中....)

編寫程式時,經常會用到別人已經寫好的模組(模組的形式不同:有些是以靜態庫方式提供,有些提供C語言的介面,有些提供C++的介面).所以在連結的時候經常遇到一些問題,特記錄

首先要明白一個道理:

.m檔案只能識別OC,C語言; 即模組是OC或C語言編寫的,就一般使用.m檔案就可以了.

.mm檔案是針對OC,C和C++三語音的; 注意模組是C++實現的,就不能在使用.m檔案,要使用.mm檔案(cpp檔案沒用過,不知情況了)

以下是一些具體編譯錯誤彙總:

問題1.


   或者


 解決方法:把.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解決.


問題3

  在音訊編解碼的時候,在使用G711a格式的時候,原始檔案是G711.c.這個在Xcode的預設編譯器中是有錯誤的,

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

問題4


解決方式:新增一個libstdc++.dylib

問題5


解決方式:


問題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];
    });
}