Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error LNK2005 already defined in card.obj

this code gives me error LNK2005 Severity Code Description Project File Line Suppression State
Error LNK2005 getCardHolderName already defined in card.obj and
Severity Code Description Project File Line Suppression State
Error LNK1169 one or more multiply defined symbols found Payment_Application
what should I do ??

  //main.c
#include <stdio.h>
#include "STD_TYPES.h"
#include "card.c"

ST_cardData_t NewCustomer;

void main(void)
{
    uint8_t x;
    x=getCardHolderName(NewCustomer.cardHolderName);
    if (x == 0)
    {
        printf("Name is Valid");
    }
    else
    {
        printf("Name is Invalid");
    }
}

//card.h
#ifndef _CARD_H
#define _CARD_H

#include "STD_TYPES.h"

typedef struct ST_cardData_t
{
    uint8_t cardHolderName[25];
    uint8_t primaryAccountNumber[20];
    uint8_t cardExpirationDate[6];
}ST_cardData_t;


typedef enum EN_cardError_t
{
    OK, WRONG_NAME, WRONG_EXP_DATE, WRONG_PAN
}EN_cardError_t;

EN_cardError_t getCardHolderName(ST_cardData_t* cardData);
EN_cardError_t getCardExpiryDate(ST_cardData_t* cardData);
EN_cardError_t getCardPAN(ST_cardData_t* cardData);
#endif

//card.c
#include "card.h"
#include <stdio.h>
#include <string.h>
#include "STD_TYPES.h"

EN_cardError_t getCardHolderName(ST_cardData_t* cardData)
{
    uint8_t validity;
    printf("Please Enter The Card Holder Name (24 characters max - 20 characters min) : ");
    fflush(stdin);
    gets(cardData->cardHolderName);
    //scanf("%[^\n]s", cardData->cardHolderName);
    if ((strlen(cardData->cardHolderName) <= 24) && (strlen(cardData->cardHolderName) >= 20))
    {
        return OK;
    }
    else
    {
        return WRONG_NAME;
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include "card.c"

It’s probably a better idea to include the header file rather than the C file.

The latter will cause duplicate symbols if you link the main object file and the card object file since main includes the exact same code as card (as a subset).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading