相关疑难解决方法(0)

包括来自另一个目录的头文件

我有一个主目录,A有两个子目录BC.

目录B包含头文件structures.c:

#ifndef __STRUCTURES_H
#define __STRUCTURES_H
typedef struct __stud_ent__
{
    char name[20];
    int roll_num;
}stud;
#endif
Run Code Online (Sandbox Code Playgroud)

目录C包含main.c代码:

#include<stdio.h>
#include<stdlib.h>
#include <structures.h>
int main()
{
    stud *value;
    value = malloc(sizeof(stud));
    free (value);
    printf("working \n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:

main.c:3:24: error: structures.h: No such file or directory
main.c: In function ‘main’:
main.c:6: error: ‘stud’ undeclared (first use in this function)
main.c:6: error: (Each undeclared identifier is reported only …
Run Code Online (Sandbox Code Playgroud)

c compiler-errors include c-preprocessor

40
推荐指数
3
解决办法
6万
查看次数

#include父目录的文件

我的文件夹结构是

libA
    x.h
    y.h
    algorithm/
        a.h
Run Code Online (Sandbox Code Playgroud)

现在,a.h我有#include "libA/x.h"哪些不起作用.它寻找algorithm/libA/x.h.我应该使用#include "../x.h"吗?第二种选择是不好的设计吗?目前libA只是标题.但后者我可能会选择将其编译为库

我正在使用cmake所以我可以或者我应该添加libA我的包含路径吗?

简而言之

我的算法目录中的某些文件需要包含其父文件夹中的定义.我无法模仿所有函数,因为类型很明显,而且会过度.那么我应该如何设计我的项目?

c++ cmake include

11
推荐指数
2
解决办法
2万
查看次数

标签 统计

include ×2

c ×1

c++ ×1

c-preprocessor ×1

cmake ×1

compiler-errors ×1