即使包含头文件,还是未定义的符号?

时间:2017-04-12 04:02:42

标签: c keil

当我尝试编译代码时,我收到错误:

.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).

我读到“声明一个函数时会发生未定义的符号错误(就像lock.h中锁定函数的情况一样),但它没有正确实现。”但我觉得我正在lock.h中正确实现所有函数,因为所有函数都是void类型而我没有return。所以我不知道我可能做错了什么来得到这个错误。

非常感谢任何帮助!

注意: 如果我需要提供更多代码,请与我们联系。我认为我不需要编写我在lock.h的函数实现中所写的内容,因为我觉得您需要知道的是函数实现不会返回任何内容,但如果我需要包含,请告诉我这一点。

代码

lock.c

#include "lock.h"

extern process_t * current_process; 
extern process_t * process_queue;

void l_init(lock_t* l){
    //Does stuff but never type return or return anything
}

void l_lock(lock_t* l){
    //Does stuff but never type return or return anything
}

void l_unlock(lock_t* l){
    //Does stuff but never type return or return anything
}

lock.h

#ifndef __LOCK_H_INCLUDED__
#define __LOCK_H_INCLUDED__

#include "3140_concur.h"
#include "shared_structs.h"

void l_init(lock_t* l);

void l_lock(lock_t* l);

void l_unlock(lock_t* l);

#endif /* __LOCK_H_INCLUDED */

3140_concur.c

#include "3140_concur.h"
#include <stdlib.h>

3140_concur.h

#ifndef __3140_CONCUR_H__
#define __3140_CONCUR_H__

#include <stdlib.h>
#include <fsl_device_registers.h>
#include "process.h"

void process_blocked (void);

void process_terminated (void);

unsigned int * process_stack_init (void (*f)(void), int n);

void process_stack_free (unsigned int *sp, int n);

void process_begin (void);

#endif

process.h

#include <stdlib.h>
#include <fsl_device_registers.h>
#include "3140_concur.h"

struct process_state;
typedef struct process_state process_t;

unsigned int * process_select (unsigned int * cursp);

extern process_t * current_process; 
extern process_t * process_queue;

void process_start (void);

int process_create (void (*f)(void), int n);

process.c

(我做process_t* process_queue = NULL; & process_t* current_process = NULL; b / c我希望在调用任何函数之前它们为NULL)

#include "3140_concur.h" 
#include "shared_structs.h"
#include <stdlib.h> 
#include <fsl_device_registers.h>

process_t* process_queue = NULL;
process_t* current_process = NULL;

lab4_t0.c

#include "process.h"
#include "utils.h"
#include "lock.h"

lock_t l;

\\uses functions in lock.h

更新

构建输出

*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling 3140_concur.c...
compiling lab4_t0.c...
lab4_t0.c(42): warning:  #111-D: statement is unreachable
        return 0;       
lab4_t0.c: 1 warning, 0 errors
compiling process.c...
process.c(100): warning:  #1-D: last line of file ends without a newline
  }
process.c: 1 warning, 0 errors
linking...
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 3 error messages.
".\Objects\Lab4.axf" - 3 Error(s), 2 Warning(s).
Target not created.
Build Time Elapsed:  00:00:39

1 个答案:

答案 0 :(得分:0)

感谢@AjayBrahmakshatriya,事实证明我没有将lock.c添加到我的项目中。这解决了一切。呼。