简体   繁体   English

没有包含头文件C的此类文件或目录错误

[英]No such file or Directory error for including header file C

I am trying to include a header file which contains a structure, but when I try to compile the file including the header file, I get No such file or Directory error. 我试图包括一个包含结构的头文件,但是当我尝试编译包含头文件的文件时,出现No such file or Directory错误。 Both .c and header file are in the same directory. .c和头文件都在同一目录中。

Here is the code: 这是代码:

Header file "MyShared.h": 头文件“ MyShared.h”:

#ifndef MYSHARED_H_INCLUDED
    #define MYSHARED_H_INCLUDED
    #define PERM (S_IRWRU | S_IRGRP)
    #define MySharedKey 0343
    #define SIZE 2048

    struct MyShared
    {
        char *buf[SIZE];
        int ReadfromBuf,WriteToBuf,readbytes;
    };
#endif

Mem.c file including the header file: Mem.c文件包括头文件:

#include <sys/shm.h>
#include "MyShared.h"

int main()
{
    MyShared *obj;

    int shmid,i,childpid;

    shmid = shmget(MySharedKey,sizeof(MyShared),NULL);

    .....
}

Why am I getting this error? 为什么会出现此错误?

In C, a struct definition is not a typedef. 在C语言中,结构定义不是 typedef。

#include <sys/shm.h>
#include "MyShared.h"


int main()
{
struct MyShared *obj;

int shmid,i,childpid;

shmid=shmget(MySharedKey, sizeof *obj, NULL);

    .....
}

BTW: I don't think you want an array of pointers in shared memory: char *buf[SIZE]; 顺便说一句:我不认为您想要共享内存中的指针数组: char *buf[SIZE]; should probably be char buf[SIZE]; 应该可能是char buf[SIZE];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM