我正在使用 icc12 制作一个包含三个文件的项目:
.s 文件,包含一系列汇编语言子程序
.h 文件,其中包含函数列表
.c 程序包含我调用子程序的主要代码
我的问题是,当我编译我的 C 程序时,编译器会显示以下错误:
!ERROR file 'filename.o': undefined symbol '_lcd_putstr'
!ERROR file 'filename.o': undefined symbol '_lcd_init'
!ERROR file 'filename.o': undefined symbol '_lcd_move'
!ERROR file 'filename.o': undefined symbol '_lcd_clear'
我一直在对 .o 文件实际上是什么进行一些研究,并且我知道它是一个包含 CPU 可以理解的机器代码的目标文件。它们包含允许链接器查看它需要哪些符号才能工作的信息。尽管如此,我仍然不明白如何解决这些错误。我检查了任何语法错误,但似乎找不到任何语法错误。是否有人能够就如何在我的 .o 文件中“定义”这些符号提供一些帮助?
我的构建命令是
#include <stdio.h>
#include <mc9s12dp512.h>
#include "lcd.h"
int main (void)
{
unsigned char keycode;
int keysave = 0;
DDRB = 0x00; /* make Port B an input port */
lcd_init(); // initialise the lcd module
lcd_clear(); // clear the lcd module
// print the welcome message on the LCD module
lcd_putstr(" message A ");
// move the cursor position down a line
lcd_move(1,1);
lcd_putstr(" message B ");
// move the cursor position down a line
lcd_move(1,2);
lcd_putstr(" message C ");
// move the cursor position down a line
lcd_move(1,3);
lcd_putstr(" message D ");
汇编文件的摘录_lcd_putstr
_lcd_putstr::
pshx
tfr d,x ; Transfer address of string to X
ldaa #WRDATA ; Set up command for write data
jsr WriteBytes ; Call subroutine to write byte to LCD
pulx
rts