gpt4 book ai didi

c - 包含带有 code::blocks 的 header

转载 作者:太空宇宙 更新时间:2023-11-04 02:55:26 25 4
gpt4 key购买 nike

因此,我在 Code::blocks 中创建了一个 C 项目。一开始它只包含 main.c 文件。然后我添加了一个 c++ 类 (gobject c) 用于将项目划分为 src 和包含文件夹,然后我将 cpp 文件中的扩展名更改为 c。

当我尝试编译时,它会给我一条消息:

fatal error: /home/user/Project_name/src/A.h: No such file or directory

所以,类名是A:

  • 标题路径:include/A.h
  • 定义路径:src/A.c

A.c 的代码(我试过 include "/include/A.h"和 include "include/A.h"但没有结果)

#include "A.h"

A.h 的代码

#ifndef A_H
#define A_H

#endif

我该如何解决这个问题?我还尝试将 A.h 包含在 main.c 中(没有结果 :( )

最佳答案

当您在 C 中包含文件时,默认情况下 C 预处理器可以在 2 个位置进行搜索:

1) #include <stdlib.h> - stdlib.h在编译器的包含搜索路径中搜索

2) #include "myLib.h" - myLib.h在当前目录中搜索(除非遍历目录)

你应该尝试做 #include "../include/A.h"src/A.c里面.

关于c - 包含带有 code::blocks 的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18110293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com