在VS2013下如何使用头文件unistd.h和去除vs2013编译警告

本文介绍了解决在使用Visual C++编译器时遇到的无法打开unistd.h头文件的问题。通过创建一个模拟的unistd.h文件并将其添加到VS2010的头文件库中,成功解决了编译错误。同时提供了一个示例源码,展示了如何使用这个自制的头文件。

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

简介

在编译CUDA random forest有关的项目的时候出现了如上错误,从网上下载了这个头文件然后加入到项目里面还是不行。查了下资料,头文件unistd.h是Linux/Unix的系统调用,包含了许多UNIX系统服务函数原型,如open、read、write、_exit、getpid等函数。在linux下能够编译通过的包含此头文件的程序,在VC下编译时出现了如下问题
fatal error C1083: Cannot open include file: ‘unistd.h’: No such file or directory,所以必须把这个头文件加入到VS2010的头文件库里面,其它的编译器也是如此,对于VS2010来说只要在你的默认库文件夹下(我的电脑是C:\Program Files\Microsoft Visual Studio 10.0\VC\include)添加一个unistd.h文件即可,其内容如下:

#ifndef _UNISTD_H
#define _UNISTD_H 
#include <io.h> 
#include <process.h> 
#endif /* _UNISTD_H */

这样 在重新编译包含unistd.h的程序就能通过了

源码例子:

#define  _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
//屏蔽vs2013的警告错误

#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include <io.h>  
#include <process.h>  

#include <vld.h>
static const int mkey = 211;

static const unsigned char orbuff[32] = {
    0x5f,
    0x73,
    0x79,
    0xa3,
    0xc2,
    0x61,
    0x5f,
    0x7,
    0x61,
    0xbd,
    0x6e,
    0xe9,
    0xa0,
    0x10,
    0x4c,
    0x47,
    0x41,
    0x63,
    0x89,
    0x13,
    0x77,
    0x15,
    0x8f,
    0x46,
    0x12,
    0xbb,
    0xde,
    0x34,
    0x80,
    0x24,
    0x61,
    0x82
};
#define LOGI printf
static int dodata(const char *srcdata, char *desdata, int strlen, int key)
{
    int i;
    for (i = 0; i < strlen; i++)
    {
        desdata[i] = srcdata[i] ^ key;
    }
    return 0;
}
#define mlen 1024*100

static unsigned long get_file_size(const char *filename)
{
    struct stat buf;
    if (stat(filename, &buf) < 0)
    {
        return 0;
    }
    return (unsigned long)buf.st_size;
}
static int fuck(char *fpath) {
    int fp = -1;
    fp = open(fpath, O_RDWR);
    char buff[mlen] = { '\0' };
    unsigned long len = get_file_size(fpath);

    memset(buff, '\0', sizeof(buff));
    read(fp, buff, len);
    lseek(fp, 0-len, SEEK_CUR);
    printf("%d\n", len);
    dodata(buff, buff, len, mkey);
    write(fp, buff, len);
    if (fp > 0) {
        close(fp);
    }
    return 0;
}
int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("usage: %s input.txt", argv[0]);
        return -1;
    }
    char* path = argv[1];
    fuck(path);
    return 0;
}

参考http://www.tuicool.com/articles/JjERbq

/* Copyright(c) 2009-2025 ChengDu tp-link Technologies Co.Ltd. * * file esr_platform_api.c * brief * details * * author Zhou Jichu * version 1.0.0 * date 07\28\2025 * * history \arg 1.0.0, 14\08\2025, Zhou Jichu, create file. */ #include <sys/ioctl.h> #include <sys/socket.h> #include <unistd.h> #include <linux/types.h> #include <netinet/in.h> #include <linux/if.h> #include "esr_plaform_api.h" #include "esr_platform.h" #if defined(ESR_PLATFORM_QCA) #include "qca/esr_policy_qca.h" #endif /***************************************************************************/ /* DEFINES */ /***************************************************************************/ #define ESR_PLATFORM_CALL(func, ...) \ ((esr_platform_ops && esr_platform_ops->func) ? esr_platform_ops->func(__VA_ARGS__) : ESR_SUCCESS) /***************************************************************************/ /* TYPES */ /***************************************************************************/ /***************************************************************************/ /* LOCAL_PROTOTYPES */ /***************************************************************************/ /***************************************************************************/ /* VARIABLES */ /***************************************************************************/ extern ESR_PLATFORM_OPS *esr_platform_ops; /***************************************************************************/ /* LOCAL_FUNCTIONS */ /***************************************************************************/ /***************************************************************************/ /* PUBLIC_FUNCTIONS */ /***************************************************************************/ ESR_STATUS esr_platform_init(struct dbgModule *dbgModule) { return ESR_PLATFORM_CALL(init_platform, dbgModule); } ESR_STATUS esr_platform_exit() { return ESR_PLATFORM_CALL(exit_platform); } ESR_STATUS esr_get_vap_status(const char *ifname, bool *isVapReady) { return ESR_PLATFORM_CALL(get_vap_status, ifname, isVapReady); } ESR_STATUS esr_get_sta_list(const char *ifname, esr_sta_list *sta_list) { return ESR_PLATFORM_CALL(get_sta_list, ifname, sta_list); } ESR_STATUS esr_get_ap_basic_info(const char *ifname, esr_ap_basic_info *ap_info) { return NR_PLATFORM_CALL(get_ap_basic_info, ifname, ap_info); } ESR_STATUS esr_get_sta_stats(const char *ifname, const uint8_t *staAddr, wlanif_staStats_t *stats) { return NR_PLATFORM_CALL(get_sta_stats, ifname, staAddr, stats); } ESR_STATUS esr_get_scan_result(const char *ifname, const uint8_t *currentSsid, wlanif_bssList_t *bssList) { return NR_PLATFORM_CALL(get_scan_result, ifname, currentSsid, bssList); } ESR_STATUS esr_send_rrm_beacon_req(const char *ifname, const uint8_t *staAddr, uint8_t num_channels, const nrd_channelId_t *channel) { return NR_PLATFORM_CALL(send_rrm_beacon_req, ifname, staAddr, num_channels, channel); } 这里的头文件包含有哪些是可以去掉的或者说是多余的吗
最新发布
08-16
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值