新人第一次发帖
我对其中要包含进去的uart.o这个文件不理解。
写了一个只输出"Hello World"的test.c文件
有一个stdio.h文件,内容为:
#ifndef _STDIO_H
#define _STDIO_H
#include "types.h"
#ifndef _VALIST
#define _VALIST
typedef char *va_list;
#endif /* _VALIST */
extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
extern int snprintf(char * buf, size_t size, const char *fmt, ...);
extern int vsprintf(char *buf, const char *fmt, va_list args);
extern int sprintf(char * buf, const char *fmt, ...);
extern int vsscanf(const char * buf, const char * fmt, va_list args);
extern int sscanf(const char * buf, const char * fmt, ...);
extern void putc(unsigned char c);
extern unsigned char getc(void);
int printf(const char *fmt, ...);
int scanf(const char * fmt, ...);
#endif /* _STDIO_H */
有一个type.h文件,内容为:
#ifndef _TPYES_H
#define _TPYES_H
#ifndef NULL
#define NULL 0
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif /* _SIZE_T */
#endif /* _TPYES_H */
Makefile文件内容是:
all:test.bin clean
test.bin:test.o libc.a uart.o
arm-linux-ld -Ttext=0x40000000 test.o libc.a uart.o -o test.elf
arm-linux-objcopy -O binary -S test.elf test.bin
test.o:test.c
arm-linux-gcc -c -nostdinc -nostdlib -fno-builtin test.c -o test.o
clean:
rm -rf ./test.o ./*elf
已经知道libc.a为静态库文件,但是那个uart.o是做什么的呢?,如果我在make的时候不将uart.o链接进去,就会出现如下错误:
libc.a(printf.o): In function `scanf':
printf.c:(.text+0x1c): undefined reference to `getc'
printf.c:(.text+0x24): undefined reference to `putc'
libc.a(printf.o): In function `printf':
printf.c:(.text+0x88): undefined reference to `putc'
make: *** [test.bin] Error 1
找了好久资料看弄不清楚uart.o的作用是什么

------解决方案--------------------
你觉得裸板printf会输出到哪呢。。裸板一般会指定输入输出设备,这里就是uart
------解决方案--------------------
你用了 uart.c 中的接口就要加入