gpt4 book ai didi

c - 在 gcc 编译器中链接自定义 header

转载 作者:行者123 更新时间:2023-11-30 17:36:32 25 4
gpt4 key购买 nike

我在编译程序时遇到问题。该程序的 header 是

#include <stdio.h>
#include <stlib.h>
#include "useCurses.h"
#include "robotModel.h"
#include "maze.h"

我尝试过使用

进行编译

gcc -I/path/to/folder program.c -o program.exe -lncurses

并收到以下错误消息:

undefined reference to (function)

对于program.c 中调用的每个函数,该函数包含在robotModel.h 或maze.h 中。文件 maze.h 和 robotsModel.h 都包含文件 maze.c 和 robotsModel.c 中定义的函数原型(prototype),所有这些文件都与 program.c 位于同一文件夹中。我在这里忘记做什么?

编辑:机器人模型.h:

#ifndef ROBOTMODEL_H
#define ROBOTMODEL_H
(function prototypes)
#endif

robotModel.c:

#include "robotModel.h"
(function definitions, no main())

迷宫.h:

#ifndef MAZE_H
#define MAZE_H

#include "robotModel.h"
(function prototypes)
#endif

迷宫.c:

#include "maze.h"
#include <stdio.h>
#include <stdlib.h>
(function definitions, no main())

当在 main() 或 program.c 中的另一个函数中调用 maze.h 或 robotsmodel.h 中定义的函数时,编译器错误会指向每个实例。

编辑2:我通过使用让它工作

gcc program.c maze.c robotModel.c -o program.exe -lncurses

最佳答案

您还应该编译 maze.crobotModel.c 源文件。 ——马赫什

关于c - 在 gcc 编译器中链接自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22647891/

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