Keil ошибка l6200e

$begingroup$

I am learning ARM programming. I’ve configured uart of lpc2148 before. But there I included entire code in single file. Today I separated them in .c and .h file. But When tried to build, I got following error

uart.axf: Error: L6200E: Symbol a multiply defined (by main.o and uart.o).
uart.axf: Error: L6200E: Symbol i multiply defined (by main.o and uart.o).
Target not created

Below is the code
main.c

//main.c

#include "uart.h"

int main(void)  {

    uart_init();
    uart_tx("Hellorn");

    while(1)
    {
        uart_rx();
        uart_tx(a);
        uart_tx("rn");
    }
    return 0;
}

uart.c

//uart.c
#include "uart.h"

void uart_init()    {
    PINSEL0 |= (5<<0);
    U0LCR = 0X83;
    U0DLL = 97;
    U0LCR = 0X03;

}

void uart_tx(char *data)    {
    while(*data)    {
        U0THR = *data;
        while(!(U0LSR&(1<<5)));
        data++;
    }
}

void uart_rx()  {
    for(i = 0; ; i++)   {
        while(!(U0LSR&(1<<0)));
        a[i] = U0RBR;

        if(a[i] == 'r')    {
            a[i] = '';
            break;
        }
    }
}

uart.h

//uart.h

#ifndef UART_H
#define UART_H

#include <LPC214X.H>
#include <stdio.h>
#include <stdint.h>

char a[100];
int i;

void uart_init();
void uart_tx(char *);
void uart_rx();

#endif

I found some links, but none of it seems to give a solution

link1

link2

asked Aug 4, 2018 at 19:07

Athul's user avatar

$endgroup$

$begingroup$

You have declared a and i in a header, so they’re being defined in each translation unit they’re compiled in. You should put them in their respective implementation files, static if they don’t need to be shared and in the smallest scope you can.

i for example is used only as a loop counter in the rx function, either declare it at the top of the function or if you’re using c99 then declare it in the loop.

answered Aug 4, 2018 at 19:12

Colin's user avatar

ColinColin

4,4592 gold badges19 silver badges33 bronze badges

$endgroup$

$begingroup$

Variables ‘a’ and ‘i’ should be declared in uart.h using the ‘extern’ attribute. Variables ‘a’ and ‘i’ should be defined in uart.c, and only in uart.c The declaration in uart.h tells the compiler about the characteristics of the two variables and the ‘extern’ attribute indicates that they are defined somewhere else (uart.c in this case).

The definition of the variables in uart.c should be outside of any function so that they have global scope. It’s a good idea to put this definition before any functions as well.

You should use better variable names, by the way.

answered Aug 4, 2018 at 19:11

Elliot Alderson's user avatar

Elliot AldersonElliot Alderson

31k5 gold badges29 silver badges67 bronze badges

$endgroup$

1

I am trying to compile my code but I get the error «multiply defined» despite defining my variable only in one header (For example «.ObjectsLCDADC.axf: Error: L6200E: Symbol Pin_D6 multiply defined (by lcd.o and main.o).».)

I am using Keil with an LPC1768

main.c

#include <lpc17xx.h>
#include "LCD.h"
#include "Delay.h"


//Char LCD Pins
#define LCD_RS P2_0
#define LCD_RW P2_1
#define LCD_E P2_2
#define LCD_D4 P2_4
#define LCD_D5 P2_5
#define LCD_D6 P2_6
#define LCD_D7 P2_7

int main(){
    SystemInit();
    Delay_init();
    LCD_Init(LCD_RS, LCD_RW, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

    int main....

LCD.H

#include "Delay.h"

uint8_t Pin_RS;
uint8_t Pin_RW;
uint8_t Pin_E;
uint8_t Pin_D4;
uint8_t Pin_D5;
uint8_t Pin_D6;
uint8_t Pin_D7;

void LCD_Init(uint8_t rs, uint8_t rw, uint8_t e, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

....(More functions)

LCD.c

#include "LCD.h"
#include "GPIO.h"
#include "Delay.h"

void LCD_Init(uint8_t rs, uint8_t rw, uint8_t e, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
{
    //Set Pin Numbers
    Pin_RW = rw;
    Pin_E = e;
    Pin_RS = rs;
    Pin_D4 = d4;
    Pin_D5 = d5;
    Pin_D6 = d6;
    Pin_D7 = d7;

    //Set port Directions
    GPIO_PinDirection(Pin_D4, 1);
    ....(same for every pin and some command sending.)

}

....(Other Functions.)

(Sorry for posting my entire code but I believe it’s important and very short in this case.)

As you can see I clearly only defined my pins only once. so why does it think I’m defining it multiple times?

This discussion has been locked.

You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I have a code with following files:

— Extern_file.h

int variable = 5;

void function (void);

— Extern_file.c

#include Extern_file.h

void function (void){ variable++; }

— main.c

#include Extern_file.h

int main(void){ function(); return 0; }

When link, I got the error:.ObjectsBlinky_LEDS.axf: Error:
L6200E: Symbol variable multiply defined (by Extern_file.o and
main.o).
Im working over a code made from component designer (stm32F105) and
migrating to nrf51822. This is only a simplified example.
Why can’t I link it?
If I use CoIDE I don’t have this problem.
I have readed another link about this problem, but I can’t solve
it.
http://www.keil.com/forum/21633/

Thanks.

  • Andy Neil

    Because, as the error message tells you, you have
    multiple definitions of the symbol
    variable‘.

    - Extern_file.h
    
    int variable = 5;
    

    That is almost certainly your problem!

    That is a definition of the symbol
    variable‘.

    Therefore, every file which #includes Extern_file.h will contain a
    definition of the symbol ‘variable‘.

    Therefore, if multiple (ie, more than one) files #include
    Extern_file.h, you will obviously have multiple
    definitions
    !!

    c-faq.com/…/decldef.html

  • Gordon Neel

    Why can’t I link it?

    Because you have two compilation units each with the

    int variable = 5;
    

    You can only initialize the variable in one unit.

    So, for example, put the

    int variable = 5;
    

    into main.c and change the header file to have just

    int variable;
    

    Advise that you read your C reference manual for definition,
    declaration and initialization.

  • Gordon Neel

    youve got an error in multiplying too bit numbers and its
    overflowing

  • Andy Neil

  • ;) not important ;)

    CONVERT YOUR VARIABLE TO DEFINE
    OR
    STOP INIT VARIABLE IN FILE «???.h» and init your variable in
    «???.cpp» ( or «???.c» )

    I solved my problem this way

    *** my english writing :)

  1. Проблема:
    Проект Keil MDK-ARM V5 построен с использованием библиотеки HAL.
    библиотека HAL обновлена ​​с STM32Cube FW_F1 V1.6.1 до STM32Cube FW_F1 V1.7.0,
    После перекомпиляции проекта, есть 102 ошибки,

    И оригинальный проект может работать правильно.
  2. Решение:
    Запрос сообщения об ошибке выглядит следующим образом:
linking...
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol SystemInit multiply defined (by system_stm32f1xx_1.o and system_stm32f1xx.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol __asm___5_adc_c_7cc13d26____REV16 multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol __asm___5_adc_c_7cc13d26____REVSH multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol __asm___5_adc_c_7cc13d26____RRX multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol hadc1 multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol HAL_ADC_MspDeInit multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol HAL_ADC_MspInit multiply defined (by adc_1.o and adc.o).
stm32_uart_mxstm32_uart_mx.axf: Error: L6200E: Symbol MX_ADC1_Init multiply defined (by adc_1.o and adc.o).
...
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.
Finished: 2 information, 0 warning and 102 error messages.
"stm32_uart_mxstm32_uart_mx.axf" - 102 Error(s), 1 Warning(s).
Target not created.
Build Time Elapsed:  00:00:21

В проекте нет файла adc_1.c.
Этапы обработки:
1. Сначала очистите весь проект, а затем перестройте все целевые файлы, но не удалось решить проблему;
2. Я искал в Интернете и обнаружил, что со мной были похожие ошибки. Затем я проверил исходные файлы c в своем проекте и обнаружил, что некоторые исходные файлы c были добавлены повторно.
Keil HAL c
Удалите избыточные исходные файлы c, перекомпилируйте и решите проблему.

Ссылка ссылка:
Ссылка ссылка

I encountered it in driving the OLED and capacitive buttons, so I recorded this error and I would not be at a loss if I encountered it again later.

Keil’s Debug picture
image

Is the definition repeated? I didn’t see it anyway when I was looking for the file

The problem is solved. The reason is that I did not declare in the header file, but directly defined the variable, and the corresponding C file did not have the definition of the variable, so this error occurred. The
solution is to move the variable in the header file directly to In the c file, and then declare in the header file, for example, in the c file, it is const unsigned char F6x8[][16]declared in the header file extern const unsigned char F6x8[][16], and that’s it!

Read More:

Like this post? Please share to your friends:
  • Keepassxc browser обнаружил ошибку не выполнен обмен ключами
  • Keep talking and nobody explodes ошибка при запуске
  • Keep camera still go pro ошибка
  • Keenetic проверка диска на ошибки
  • Keenetic ошибка соединения