c - 从另一个文件中未定义的对“功能”的引用
问题描述
我不知道问题出在哪里,我已经在头文件中定义了函数,并且我在主文件中使用包含“stack.h”调用它,未定义的对“init”的引用所有 3 个都位于同一个文件中
主要的
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
int main()
{
struct Stack s1;
int choice;
init(&s1,5);
堆栈.c
#include "stack.h"
void init(struct Stack *st, int size)
{
st->pin = (int *) malloc(size * sizeof(int));
st->head = 0;
st->size = size;
}
int push(struct Stack *st, int element)
{
if (st->head == st->size)
{
return 0;
}
st->pin[st->head] = element;
st->head++;
return 1;
}
int pop(struct Stack *st, int *element)
{
if(st->head == 0)
{
return 0;
}
st->head--;
*element = st->pin[st->head];
return 1;
}
堆栈.h
#ifndef stack
#define stack
struct Stack{
int *pin;
int head;
int size;
};
void init(struct Stack *st, int size);
int push(struct Stack *st, int element);
int pop(struct Stack *st, int *element);
#endif
解决方案
您是否使用 Linux makefile/vc++ 项目来构建可执行文件。
在 linux makefile 用语中,您需要链接 stack.o 和 main.o(通过编译 stack.c 和 main.c 创建)来创建最终的可执行文件。(vc++ 项目应该在幕后为您完成)
您看到的确切错误是什么
推荐阅读
- php - 使用 jQuery ajax() 将数据发送到 php 页面时未设置会话变量
- java - 如果覆盖的保留策略是源,则运行时多态性如何工作
- swift - UITextField、textRect、Xcode 版本 10.0、部署目标 12.0、Swift 4.2
- azure-devops - 更改要由 Azure Active Directory 备份的现有组织
- c# - 无法在 Windows 窗体 C# 上粘贴控件
- google-cloud-platform - 从 Google Instance 连接 google cloud SQL
- jquery - 在 jQuery datepicker 上禁用星期一和星期六
- javascript - 我想使用 Highchart 开发蜘蛛网图/雷达图
- angular - TypeScript 编译中缺少 ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中
- javascript - 谷歌地图折线不显示和抛出错误