错误:未知类型名称';u#u char';在OSX 10.11.2中
我是osx新手,遇到了一些问题。我尝试生成文件,但得出以下结论:错误:未知类型名称';u#u char';在OSX 10.11.2中,c,makefile,gnu-make,C,Makefile,Gnu Make,我是osx新手,遇到了一些问题。我尝试生成文件,但得出以下结论: 错误:未知类型名称“u_char”;你是说“char”吗? 我提到,将-D_BSD_SOURCECFLAGS添加到我的makefile中,但没有帮助。我缺少什么 编辑: 这是产生错误的代码: char *computePwd(const u_char *md5) { static char buf[16]; unsigned char tmp[40]; int tmpl=0; tmpl = strl
错误:未知类型名称“u_char”;你是说“char”吗?
我提到,将-D_BSD_SOURCE
CFLAGS添加到我的makefile中,但没有帮助。我缺少什么
编辑:
这是产生错误的代码:
char *computePwd(const u_char *md5) {
static char buf[16];
unsigned char tmp[40];
int tmpl=0;
tmpl = strlen(userName);
strcpy((char*)tmp, userName);
memcpy(tmp + tmpl, md5, 16);
tmpl += 16;
memcpy(buf, ComputeHash(tmp, tmpl), 16);
memset(tmp, 0, 16);
strcpy((char*)tmp, password);
int i;
for (i=0; i<16; ++i)
buf[i] ^= tmp[i];
return buf;
}
char*computePwd(const u_char*md5){
静态字符buf[16];
无符号字符tmp[40];
int-tmpl=0;
tmpl=strlen(用户名);
strcpy((char*)tmp,用户名);
memcpy(tmp+tmpl,md5,16);
tmpl+=16;
memcpy(buf,ComputeHash(tmp,tmpl),16);
memset(tmp,0,16);
strcpy((char*)tmp,密码);
int i;
对于(i=0;i添加-Du_char=“unsigned char”
到CFLAGS
或只是修复源代码。在遗留BSD代码库中,使用u_char
作为无符号char
的惰性速记是一种常见做法,其中系统头历史上公开了此类typedef。不应在现代代码中使用它。或者您可以添加
#ifdef __APPLE__
#include <sys/types.h>
#endif
添加-D_DARWIN_C_SOURCE
它应该可以工作。你能发布产生错误的代码吗?char*computePwd(const u_char*md5){static char buf[16];unsigned char tmp[40];int tmpl=0;tmpl=strlen(userName);strcpy((char*)tmp,userName);memcpy(tmp+tmpl,md5,16);tmpl+=16;memcpy(buf,ComputeHash(tmp,tmpl),16);memset(tmp,0,16);strcpy((char*)tmp,password);int i;for(i=0;如果可能的话,最好在源代码处修复该错误。OP不说明错误出现的位置,因此应首先使用此选项。@Olaf:哪个更好取决于OP正在做什么。对于在新软件中重用现有代码或主动移植现有软件,修复它当然更可取。但对于仅部署现有的leg来说,修复它更可取acy软件/库在现代平台上只需最少的麻烦和维护工作,将-D
添加到CFLAGS
可能是最合理的方法。这是我的想法。只需添加-D
定义了一个宏,它是文本替换,而不是typedef
或类似的。宏可能会产生意想不到的副作用,bec因为他们不关心正常的C语法。@R..我把所有的u_字符都改成了无符号字符,效果很好!谢谢!没什么大不了的,但值得一提的是:包括sys/types.h在FreeBSD上解决了同样的问题。
typedef unsigned char u_char;