VS编程问题-warning C4996: ’strdup’

本文解决了一个常见的VS编程问题,即使用strdup时出现的版本不兼容警告C4996。通过修改预处理器定义和清理项目文件,可以有效避免此类警告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VS编程问题-warning C4996: ’strdup’(版本不兼容问题)


warningC4996: 'strdup': The POSIX name for this item is deprecated. Instead, use theISO C++ conformant name: _strdup.

 

解决方法:(借鉴别人的方法,一段时间没问题,后来又不行了)

_CRT_SECURE_NO_WARNINGS

单击要运行的项目——>属性——>C/C++(配置属性)——>预处理器——>预处理器定义——>添加“_CRT_SECURE_NO_WARNINGS”

注:添加双引号中的内容,与前一项用分号‘;’隔开。

 

后来。。。

在进行大量修改的时候,却发现删了debug下的*.pdb文件后,重新编译生成。没问题了,其他类似这种问题也不见了,我也是呵呵了。

 

建议仅供参考,且行且改吧!!!

test2.c: In function ‘execute_script’: test2.c:22:34: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration] 22 | result = realloc(result, strlen(result) + strlen(buffer) + 1); | ^~~~~~ test2.c:22:34: warning: incompatible implicit declaration of built-in function ‘strlen’ test2.c:7:1: note: include ‘<string.h>’ or provide a declaration of ‘strlen’ 6 | #include <security/pam_appl.h> +++ |+#include <string.h> 7 | test2.c:23:9: warning: implicit declaration of function ‘strcat’ [-Wimplicit-function-declaration] 23 | strcat(result, buffer); | ^~~~~~ test2.c:23:9: warning: incompatible implicit declaration of built-in function ‘strcat’ test2.c:23:9: note: include ‘<string.h>’ or provide a declaration of ‘strcat’ test2.c: In function ‘pam_conversation’: test2.c:39:31: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration] 39 | (*resp)[i].resp = strdup((char*)appdata); // 使用预设密码 | ^~~~~~ test2.c:39:31: warning: incompatible implicit declaration of built-in function ‘strdup’ test2.c: In function ‘show_x11_dialog’: test2.c:75:30: warning: incompatible implicit declaration of built-in function ‘strdup’ 75 | char* msg_copy = strdup(message); | ^~~~~~ test2.c:76:26: warning: implicit declaration of function ‘strtok’; did you mean ‘strtoq’? [-Wimplicit-function-declaration] 76 | char* line = strtok(msg_copy, "\n"); | ^~~~~~ | strtoq test2.c:76:26: warning: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] test2.c:81:53: warning: incompatible implicit declaration of built-in function ‘strlen’ 81 | MARGIN, y_pos, line, strlen(line)); | ^~~~~~ test2.c:81:53: note: include ‘<string.h>’ or provide a declaration of ‘strlen’ test2.c:82:22: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 82 | line = strtok(NULL, "\n"); | ^ /usr/bin/ld: 找不到 -lXutf8 collect2: error: ld returned 1 exit status
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值