2016-11-23 16 views
-2

lab7.c라는 파일이 있고 .o 파일로 컴파일하면 모든 것이 정상입니다. 그러나 나는 내가 시도하고이 문제를 해결하고 캔트 무엇을 찾기 위해 사방 보았다.o 파일을 .elf 파일로 만들려면 어떻게해야합니까?

lab7.o:(.data+0x8): undefined reference to `lcd_putc' 
    lab7.o: In function `main': 
    lab7.c:(.text.startup+0x0): undefined reference to `lcd_init' 
    collect2: error: ld returned 1 exit status 

의 오류 메시지가

avr-gcc -mmcu=atmega324a -o lab7.elf lab7.o 

로에게 .elf 파일을 이동합니다. 내가하려는 것은이 코드를 내 브레드 보드에 업로드하는 것뿐입니다. 내가 lab7.c

C.

에 맥 OS 시에라 쓰기에 터미널을 사용하고

#include <avr/io.h>  
#include <stdio.h> 
#include "lcd.h" 

static FILE lcd_stdout=FDEV_SETUP_STREAM(lcd_putc,NULL,_FDEV_SETUP_WRITE); 

#define PUSHED 1 
#define RIGHT_BUTTON ((PINA&_BV(PIN3)) >> 3) 
#define LEFT_BUTTON ((PINA&_BV(PIN0)) >> 0) 

#define LEFTMOST 0b10000000 
#define RIGHTMOST 0b00000001 

int main(void) { 
enum states { left_serve, right_serve, moving_left, moving_right}; 



// Include the following variable declarations here 
char state;  // This variable holds the current state 
char leds;  // Current "court" --- inverse of PORTC 

lcd_init();  // If you want to write to the LCD 
stdout=&lcd_stdout; 

// Required setup for I/O pins 
DDRD = 0xFF;  // All PORTD pins are outputs 
DDRA = 0x10;  // PORTA pin 4 is an output, rest inputs 
PORTA |= 0x10;  // Only pin 4 is important - should be 1 

// Initialize "state" to "left_serve" here 
state=left_serve; 

if (LEFT_BUTTON == PUSHED) { 
    if (leds == LEFTMOST) { 
     state = moving_right; 
    } 
    else 
    { 
     state = right_serve; 
    } 
} 
if (RIGHT_BUTTON == PUSHED){ 
    if (leds == RIGHTMOST) { 
     state = moving_left; 
    } 
    else 
    { 
     state = left_serve; 
    } 
} 
if (RIGHT_BUTTON != PUSHED && LEFT_BUTTON != PUSHED && leds == 0x00) { 
    if (state == moving_right) { 
     state = left_serve; 
    } 
    else 
    { 
     state = right_serve; 
    } 
} 
switch (state) { 

    case moving_left: 
    leds = leds << 1; 
    break; 

    case moving_right: 
    leds = leds >> 1; 
    break; 

    case right_serve: 
    leds = RIGHTMOST; 
    break; 

    case left_serve: 
    leds = LEFTMOST; 
    break; 
}  
void setLEDs(int leds) { 
PORTD= (leds^0x00FF); 
PORTC= (((~leds)>>8)&0x0003)+(PORTC&0xFFFC); 
} 

}  

lcd.h

lcd.h 내 교사가 나에게 주어졌다
#ifndef __LCD_H__ 
#define __LCD_H__ 

// A. Sheaff 1/10/2008 
// 4 bit LCD interface. 

// Define LCD type. Choose one. 
// #define LCD_1LINE 
// #define LCD_2LINE 
#define LCD_4LINE 
// End choice. 

// Set line length 
#define LCD_LINELEN 16 
// Set New line address 
#define LCD_LINE2A 0x40 

// Register select, Read/Write, Clock 
#define LCD_RS PIN4 
#define LCD_RW PIN6 
#define LCD_E PIN7 
// Code assumes lower 4 bits are for data. 
#define LCD_DATW PORTB 
#define LCD_DATR PINB 

// LCD commands 
#define LCD_CLR  0x01 // LCD Clear 
#define LCD_HOME 0x02 // LCD Home 
#define LCD_SETDD 0x80 // LCD Set Data Address 
#define LCD_SHIFT 0x10 // Shift 
#define LCD_SCURS 0x00 // Shift Cursor 
#define LCD_SDISP 0x08 // Shift Dislay 
#define LCD_SRGHT 0x04 // Shift Right 
#define LCD_SLEFT 0x00 // Shift Left 

// LCD initialization 
void lcd_init(void); 

// Wait for LCD to finish current operation. Returnds DD RAM address. 
unsigned char lcd_busy_wait(void); 

// Write character data to LCD 
void lcd_dwrite(unsigned char d); 
int lcd_putc(char c, struct __file * f); 

// Write instruction data to LCD 
void lcd_iwrite(unsigned char d); 

// Read data memory 
unsigned char lcd_dread(void); 
#endif // __LCD_H__ 

그러므로 내가 돈 ' lcd.c라는 파일이 있습니다

+0

링커 오류가 있습니다. make 파일과'lcd_putc'과'lcd_init'가 선언 된 헤더 파일과 .c 파일을 추가하십시오. –

+0

어떻게해야합니까? –

+0

avr-gcc를 실행하는 디렉토리에서 Makefile이라는 파일이어야합니다. 질문을 편집하고 추가 할 수 있습니다. 또한 링커는'lcd_putc'와'lcd_init' (함수?)를 찾지 못하기 때문에 소스 코드/파일을 호출하고 선언하고 구현하는 곳에 추가하십시오. –

답변

1

오브젝트 파일 lab7.o는 c 파일 중 하나의 코드만을 가지고 있습니다. 실행 파일 전체의 일부일뿐입니다.

실행 파일을 만들려면 모든 파트를 연결해야합니다. 표시 한 코드에서 LCD 기능으로 부품이 누락 된 것처럼 보입니다. lcd.o라는 파일이 있습니까? 시도해보십시오.

avr-gcc -mmcu=atmega324a -o lab7.elf lab7.o lcd.o 

LCD 기능이 라이브러리 또는 보관 파일에있을 수도 있습니다. 이 경우 다른 방법으로 연결해야하지만 gcc 명령의 일부 여야합니다.

모든 소스 파일 (.c 및 .h)이있는 경우 소스에서 gcc 명령 하나로 .elf까지 컴파일 할 수 있습니다.

avr-gcc -mmcu=atmega324a -o lab7.elf lab7.c lcd.c lcd.h 
+0

lcd.o라는 파일이 없으며 lcd.h라는 파일 만 있습니다. –