当前位置: 技术问答>linux和unix
makefile链接的问题
来源: 互联网 发布时间:2015-12-29
本文导语: 我在移植ucos到avr平台的时候出了点错,望高手指点! 编译环境:winavr makefile所在目录下有以下文件:(为了限制长度,故会省略一些) 1.includes.h 内容如下: #include #include #include #include "os_cpu.h"...
我在移植ucos到avr平台的时候出了点错,望高手指点!
编译环境:winavr
makefile所在目录下有以下文件:(为了限制长度,故会省略一些)
1.includes.h 内容如下:
#include
#include
#include
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
#include "pc.h"
2.os_cpu.h
......(只是一些宏定义,全部省略)
3.os_cfg.h
......(也只是一些宏定义,全部省略)
4.ucos_ii.h
#ifdef __cplusplus
extern "C" {
#endif
......(只是一些宏定义,以下全部省略)
5.pc.h
......(一些宏定义和函数原型,全部省略)
6.ucos_ii.c
#define OS_GLOBALS // Declare GLOBAL variables
#include "includes.h"
#define OS_MASTER_FILE //Prevent the following files from including includes.h
#include "os_core.c"
#include "os_flag.c"
#include "os_mbox.c"
#include "os_mem.c"
#include "os_mutex.c"
#include "os_q.c"
#include "os_sem.c"
#include "os_task.c"
#include "os_time.c"
7.os_core.c,os_flag.c,os_mbox.c,os_mem.c,os_mutex.c,os_q.c,os_sem.c,os_task.c,os_time.c九个c文件,每个文件的开头都一样
#ifndef OS_MASTER_FILE
#include "includes.h"
#endif
.........(以下省略)
8.os_cpu_c.c
#define OS_CPU_GLOBALS
#include "includes.h"
.......(以下是各个函数的具体实现,省略)
9.os_cpu_a.S,只是个汇编程序
#define OS_CPU_A
#include "os_cpu.h"
.......(以下是汇编程序,省略)
10.test.c
主程序,其实是空的
我的makefile要编译的是三个c文件,依次是:ucos_ii.c os_cpu_c.c test.c
但make的时候,编译没出错,连接的时候却错了,大体是找不到函数定义。
可为什么编译的时候没错呢?
错误如下:
Linking: testpp.elf
avr-gcc -mmcu=atmega128 -I. -gdwarf-2 -DF_CPU=14745600UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -Wa,-adhlns=/ucos_ii.o -std=gnu99 -Wundef -MD -MP -MF .dep/testpp.elf.d /ucos_ii.o /os_cpu_c.o /os_cpu_a.o --output testpp.elf -Wl,-Map=testpp.map,--cref -lm
D:/WinAVR/bin/../lib/gcc/avr/3.4.6/../../../../avr/lib/avr5/crtm128.o: In function `__vectors':
../../../../../avr-libc-1.4.4/crt1/gcrt1.S:51: undefined reference to `main'
/ucos_ii.o: In function `OS_TaskIdle':
D:hahagcc1/os_core.c:1138: undefined reference to `OSTaskIdleHook'
/ucos_ii.o: In function `OS_TCBInit':
D:hahagcc1/os_core.c:1361: undefined reference to `OSTCBInitHook'
/ucos_ii.o: In function `OSInit':
D:hahagcc1/os_core.c:233: undefined reference to `OSInitHookBegin'
D:hahagcc1/os_core.c:262: undefined reference to `OSInitHookEnd'
/os_cpu_a.o:os_cpu_a.S:324: relocation truncated to fit: R_AVR_13_PCREL against symbol `OSTimeTick' defined in .text section in /ucos_ii.o
/os_cpu_a.o:os_cpu_a.S:326: relocation truncated to fit: R_AVR_13_PCREL against symbol `OSIntExit' defined in .text section in /ucos_ii.o
make.exe: *** [testpp.elf] Error 1
> Process Exit Code: 2
> Time Taken: 00:02
请高手不吝赐教!
编译环境:winavr
makefile所在目录下有以下文件:(为了限制长度,故会省略一些)
1.includes.h 内容如下:
#include
#include
#include
#include "os_cpu.h"
#include "os_cfg.h"
#include "ucos_ii.h"
#include "pc.h"
2.os_cpu.h
......(只是一些宏定义,全部省略)
3.os_cfg.h
......(也只是一些宏定义,全部省略)
4.ucos_ii.h
#ifdef __cplusplus
extern "C" {
#endif
......(只是一些宏定义,以下全部省略)
5.pc.h
......(一些宏定义和函数原型,全部省略)
6.ucos_ii.c
#define OS_GLOBALS // Declare GLOBAL variables
#include "includes.h"
#define OS_MASTER_FILE //Prevent the following files from including includes.h
#include "os_core.c"
#include "os_flag.c"
#include "os_mbox.c"
#include "os_mem.c"
#include "os_mutex.c"
#include "os_q.c"
#include "os_sem.c"
#include "os_task.c"
#include "os_time.c"
7.os_core.c,os_flag.c,os_mbox.c,os_mem.c,os_mutex.c,os_q.c,os_sem.c,os_task.c,os_time.c九个c文件,每个文件的开头都一样
#ifndef OS_MASTER_FILE
#include "includes.h"
#endif
.........(以下省略)
8.os_cpu_c.c
#define OS_CPU_GLOBALS
#include "includes.h"
.......(以下是各个函数的具体实现,省略)
9.os_cpu_a.S,只是个汇编程序
#define OS_CPU_A
#include "os_cpu.h"
.......(以下是汇编程序,省略)
10.test.c
主程序,其实是空的
我的makefile要编译的是三个c文件,依次是:ucos_ii.c os_cpu_c.c test.c
但make的时候,编译没出错,连接的时候却错了,大体是找不到函数定义。
可为什么编译的时候没错呢?
错误如下:
Linking: testpp.elf
avr-gcc -mmcu=atmega128 -I. -gdwarf-2 -DF_CPU=14745600UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -Wa,-adhlns=/ucos_ii.o -std=gnu99 -Wundef -MD -MP -MF .dep/testpp.elf.d /ucos_ii.o /os_cpu_c.o /os_cpu_a.o --output testpp.elf -Wl,-Map=testpp.map,--cref -lm
D:/WinAVR/bin/../lib/gcc/avr/3.4.6/../../../../avr/lib/avr5/crtm128.o: In function `__vectors':
../../../../../avr-libc-1.4.4/crt1/gcrt1.S:51: undefined reference to `main'
/ucos_ii.o: In function `OS_TaskIdle':
D:hahagcc1/os_core.c:1138: undefined reference to `OSTaskIdleHook'
/ucos_ii.o: In function `OS_TCBInit':
D:hahagcc1/os_core.c:1361: undefined reference to `OSTCBInitHook'
/ucos_ii.o: In function `OSInit':
D:hahagcc1/os_core.c:233: undefined reference to `OSInitHookBegin'
D:hahagcc1/os_core.c:262: undefined reference to `OSInitHookEnd'
/os_cpu_a.o:os_cpu_a.S:324: relocation truncated to fit: R_AVR_13_PCREL against symbol `OSTimeTick' defined in .text section in /ucos_ii.o
/os_cpu_a.o:os_cpu_a.S:326: relocation truncated to fit: R_AVR_13_PCREL against symbol `OSIntExit' defined in .text section in /ucos_ii.o
make.exe: *** [testpp.elf] Error 1
> Process Exit Code: 2
> Time Taken: 00:02
请高手不吝赐教!
|
"但make的时候,编译没出错,连接的时候却错了,大体是找不到函数定义。
可为什么编译的时候没错呢? "
有一些版本的gcc 就是这样子的,你在头文件里把函数声明一下试试看。
最好把你的makefile贴出来。
可为什么编译的时候没错呢? "
有一些版本的gcc 就是这样子的,你在头文件里把函数声明一下试试看。
最好把你的makefile贴出来。