搜索
bottom↓
回复: 12

WinAVR GCC怎样编译多个C源文件???

[复制链接]

出0入8汤圆

发表于 2007-10-11 16:34:07 | 显示全部楼层 |阅读模式


按KEIL C 方法在GCC中不能通过编译.

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入8汤圆

 楼主| 发表于 2007-10-11 17:19:07 | 显示全部楼层
#include <avr/io.h>

// 函数声明
static void Delay(void);
static void Port_Init(void);

int main(void)
{
        unsigned char loop;
        unsigned char Display_Code[8]=
        {
                0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80       
        };
       
        Port_Init();

    while (1)
    {
                for (loop=0; loop<8; loop++)
                {
                        PORTB = Display_Code[loop];
                        Delay();
                }
     }
}


void Delay(void)
{
        unsigned char x, y;
    for (x=0; x<255; x++)
    {
             for (y=0; y<255; y++);
        for (y=0; y<255; y++);
    }
}


void Port_Init(void)
{
        DDRB = 0xff;        // 置PORTB端口为输出方向
        PORTB = 0xff;        // portb所有端口输出高电平
       
}

> "make.exe" all

-------- begin --------
avr-gcc (GCC) 3.4.1
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: main.c
avr-gcc -c -mmcu=atmega8 -I. -gstabs   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=gnu99 -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.o.d main.c -o main.o

Linking: main.elf
avr-gcc -mmcu=atmega8 -I. -gstabs   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o  -std=gnu99 -Wp,-M,-MP,-MT,main.o,-MF,.dep/main.elf.d main.o   --output main.elf -Wl,-Map=main.map,--cref    -lm

Creating load file for Flash: main.hex
avr-objcopy -O ihex -R .eeprom main.elf main.hex

Creating load file for EEPROM: main.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex main.elf main.eep

Creating Extended Listing: main.lss
avr-objdump -h -S main.elf > main.lss

Creating Symbol Table: main.sym
avr-nm -n main.elf > main.sym

Size after:
main.elf  :
section    size      addr
.text       172         0
.data         8   8388704
.bss          0   8388712
.noinit       0   8388712
.eeprom       0   8454144
.stab       756         0
.stabstr   1291         0
Total      2227



Errors: none
-------- end --------


> Process Exit Code: 0

象这样中同一个源文件中可以编译成功,为什么???

出0入0汤圆

发表于 2007-10-11 17:32:05 | 显示全部楼层
需要修改Makefile文件

出0入8汤圆

 楼主| 发表于 2007-10-11 18:26:17 | 显示全部楼层
怎样修改Makefile文件才能多个源文件一起来编译呢?

出0入8汤圆

 楼主| 发表于 2007-10-13 08:03:32 | 显示全部楼层
通过自己的摸索,在GCC中编译多个文件成功;
修改makefile文件如下:
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c Sys_Init.c Delay.c

出0入0汤圆

发表于 2007-10-14 11:46:14 | 显示全部楼层
好好学习,我也是刚用GCC,就是GCC如果编译出错不指示具体是哪一句,比较的麻烦.我是用GCC+UltraEdit-32做编译环境的

出0入0汤圆

发表于 2007-10-20 21:07:10 | 显示全部楼层
SRC = main.c Sys_Init.c Delay.c

出0入0汤圆

发表于 2007-11-4 20:51:06 | 显示全部楼层
学习一下,

出0入0汤圆

发表于 2007-11-4 21:12:42 | 显示全部楼层
学习

出0入0汤圆

发表于 2008-7-4 09:31:16 | 显示全部楼层
摸索ing.

出0入0汤圆

发表于 2008-7-4 09:34:23 | 显示全部楼层
MAKEFILE :

##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c timer0.c analog.c twislave.c BLMC.c
#printf_P.c
##########################################################################################################

# If there is more than one source file, append them above, or modify and
# uncomment the following:
#SRC += foo.c bar.c

# You can also wrap lines by appending a backslash to the end of the line:
#SRC += baz.c \
#xyzzy.c

# List Assembler source files here.
# Make them always end in a capital .S.  Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =

出0入0汤圆

发表于 2008-7-4 09:35:50 | 显示全部楼层
请问大家 makefile中没有src也能编译成功,是不是不能用呢?

出0入0汤圆

发表于 2008-7-4 12:26:07 | 显示全部楼层
SRC = $(wildcard *.c) $(wildcard inc/*.c)

然后做成模版,不用每次修改了。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-6-9 16:33

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表