strndup怎么了? [英] What's wrong with strndup?

查看:78
本文介绍了strndup怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用flex编写解析器.我正在使用Mac OS X 10.6.7. 我已经包含了这样的头文件:

I'm writing a parser using flex. I'm using Mac OS X 10.6.7. I have already include header files like this:

#include "string.h"
#include "stdlib.h"

但它说

Undefined symbols for architecture x86_64:
  "_strndup", referenced from:
      _yylex in ccl2332A.o
ld: symbol(s) not found for architecture x86_64

为什么?

推荐答案

AFAIK string.h或stdlib.h中没有方法strndup,请尝试使用strdup(),这可能是您想要的.如果您确实需要指定要分配的长度,则可以使用malloc和memcpy代替.

AFAIK there is no method strndup in string.h or stdlib.h, try using strdup() which is probably what you want. If you really need to specifiy the length you want allocated you could do it using malloc and memcpy instead.

这篇关于strndup怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆