gpt4 book ai didi

c - 将多个目标文件链接到二进制 AVR GCC

转载 作者:行者123 更新时间:2023-11-30 14:55:29 25 4
gpt4 key购买 nike

我有以下 header 和源文件:

AVR_comunic.h

#ifndef AVR_COMUNIC_H_
#define AVR_COMUNIC_H_

#include<avr/io.h>

#define FOSC 20000000UL // Clock Speed
#define BAUD 19200
#define MYUBRR FOSC/16/BAUD-1

void USART_Init( unsigned int);
int USART_WriteChar(unsigned char);
// int USART_Receive( unsigned char *);
void USART_Flush(void);

#endif /* AVR_COMUNIC_H_ */

AVR_comunic.c

#include "AVR_comunic.h"

void USART_Flush( void )
{
...
}

void USART_Init( unsigned int ubrr)
{
...
}

int USART_WriteChar(unsigned char data)
{
...
}

和main_f.c

#include"AVR_comunic.h"

void init_ports()
{
DDRD|= (1<<PD7);
}

int main(void)
{
init_ports();
...
while(1)
{
// now what?
}
return 1;
}

我在Notepad++中编写了一个批处理文件来获取该程序的.hex文件

COMPILE_BUILD.bat

ECHO OFF
ECHO ----------------------------------------------------------
ECHO ----- executing your commands : compile and build -------
ECHO ----------------------------------------------------------
avr-gcc -g -Wall -Os -DF_CPU=20000000UL -mmcu=atmega88p -c AVR_comunic.c
avr-gcc -g -Wall -Os -DF_CPU=20000000UL -mmcu=atmega88p -c main_f.c

avr-gcc -g -mmcu=atmega88p -o AVR_comunic.elf main_f.o AVR_comunic.o

avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst
avr-gcc -g -mmcu=atmega8 -Wl,-Map,AVR_comunic.map -o AVR_comunic.elf AVR_comunic.o
avr-objcopy -j .text -j .data -O ihex AVR_comunic.elf AVR_comunic.hex
ECHO ----------------------------------------------------------
ECHO ---------------------- happy ? ---------------------------
ECHO ----------------------------------------------------------
pause

我收到以下错误:

... : undefined reference to 'main'
avr-objcopy: 'AVR_comunic.elf' no such file

我从互联网上的信息了解到链接器确实认为没有“主要”功能......但它是......我做错了什么?或者我应该如何编写来编译多个源文件?

最佳答案

I understand from the information on internet that the linker does thinks that there is no "main" function ... but it is ... what am I doing wrong?

此命令:

avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst

尝试从尚未生成的AVR_communic.elf中提取信息。您想在执行此命令后移动它:

avr-gcc -g -mmcu=atmega8 -Wl,-Map,AVR_comunic.map -o AVR_comunic.elf AVR_comunic.o

上述命令失败, undefined reference :'main',因为您没有main_f.o链接到其中。

看来您真正想要的是:

avr-gcc -g -mmcu=atmega88p -o AVR_communic.elf main_f.o AVR_comunic.o
avr-objdump -h -S AVR_comunic.elf > AVR_comunic.lst
avr-objcopy -j .text -j .data -O ihex AVR_comunic.elf AVR_comunic.hex

关于c - 将多个目标文件链接到二进制 AVR GCC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45828357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com