xcode 编译旧程序遇到的一些问题解决汇总

1、Implicit declaration of function 'inet_addr' is invalid in C99
添加 #include <arpa/inet.h>
2、Implicit declaration of function 'read' is invalid in C99
Implicit declaration of function 'write' is invalid in C99
Implicit declaration of function 'close' is invalid in C99

相应的改为 fread,fwrite,fclose,对应函数的参数也要调整
3、Implicit declaration of function 'access' is invalid in C99
添加 #include <unistd.h>
#include <fcntl.h>
4、Implicit declaration of function 'sign_extend' is invalid in C99

在Linux Kernel 的源文件里有定义

static __inline int
sign_extend(int n, int num_bits)
{
  int shift = (int)(sizeof(int) * 8 - num_bits);
  return (n << shift) >> shift;
}

5、Cast from pointer to smaller type 'unsigned int' loses information

替换 为 uintptr_t
6、Implicit conversion loses integer precision: 'long' to 'int'
7、ISO C++11 does not allow conversion from string literal to 'char *<span style="font-family: Arial, Helvetica, sans-serif;">'</span>
<span style="font-family:Arial, Helvetica, sans-serif;">方法一将函数参数声明为 const char *,方法二、字符串前加 (char *)进行显式转换</span>
8、CodeSign error: code signing is required for product type 'OCUnit Test Bundle' in SDK 'iOS 8.1'

Edit Scheme 的 build ,去掉 test 的选中
9、网络接口调用失败,提示"NSLocalizedDescription" "unsupported URL"

在URL中如果包含汉字或特殊符号,需要转码到UTF8
    NSString *url = @"http://www.testcode.com/test/rest/messReceived?messag=content:{name:\"zhj\"}";
    url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    NSLog(@"url %@",url);
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];

你可能感兴趣的:(xcode 编译旧程序遇到的一些问题解决汇总)