Duplicate variable declarations

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Duplicate variable declarations

97 Views
Julian99
Contributor III

I am working on a new project using the LPC824 board and the downloaded lpcxpresso824max_new_project. It built, downloaded and debugged without problems. Initially I am trying to implement a 3-digit 7-segment LED display. I added declarations in peripherals.h and an update routine in main.c. When I build I get two errors - duplicated variable declarations. If I comment them out I get a message "undeclared variable". If I change the name of the variable I get the same duplication error. I have searched every source file in the project and cannot find any duplicates. One of the error messages is: -

/Applications/MCUXpressoIDE_25.6.136/ide/plugins/com.nxp.mcuxpresso.tools.macosx_25.6.0.202501151204/tools/bin/../lib/gcc/arm-none-eabi/14.2.1/../../../../arm-none-eabi/bin/ld: ./source/peripherals.o:/Users/julian/Documents/MCUXpressoIDE_25.6.136/workspace/lpcxpresso824max_new_project/Debug/../source/peripherals.h:57: multiple definition of `CA_LUT'; ./source/main.o:/Users/julian/Documents/MCUXpressoIDE_25.6.136/workspace/lpcxpresso824max_new_project/Debug/../source/peripherals.h:57: first defined here

 

0 Kudos
Reply
3 Replies

31 Views
Julian99
Contributor III

This is the entry in peripherals.h for both errors

// Lookup table for digits 0-9 (0 = ON, 1 = OFF)
const uint32_t CA_LUT[10] = {
//0: A, B, C, D, E, F are ON; G, DP are OFF
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_E)|(1<<SEG_F)),
// 1: B, C are ON
~((1<<SEG_B)|(1<<SEG_C)),
// 2: A, B, D, E, G are ON
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_D)|(1<<SEG_E)|(1<<SEG_G)),
// 3: A, B, C, D, G are ON
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_G)),
// 4: B, C, F, G are ON
~((1<<SEG_B)|(1<<SEG_C)|(1<<SEG_F)|(1<<SEG_G)),
// 5: A, C, D, F, G are ON
~((1<<SEG_A)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_F)|(1<<SEG_G)),
// 6: A, C, D, E, F, G are ON
~((1<<SEG_A)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_E)|(1<<SEG_F)|(1<<SEG_G)),
// 7: A, B, C are ON
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_C)),
// 8: All segments ON (A-G)
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_E)|(1<<SEG_F)|(1<<SEG_G)),
// 9: A, B, C, D, F, G are ON
~((1<<SEG_A)|(1<<SEG_B)|(1<<SEG_C)|(1<<SEG_D)|(1<<SEG_F)|(1<<SEG_G))
};

// Global variables holding the current numbers to be printed on Digits 1, 2, and 3
volatile uint8_t display_buffer[3] = {1, 2, 3}; // E.g., displays "123"

Both errors are used in main.c :-

uint8_t numeric_value = display_buffer[current_digit];
uint32_t segment_pattern = CA_LUT[numeric_value];

#include "peripherals.h" appears only in the following files: -

main.c, peripherals.c, 

AS I mentioned I am coming over from CodeWarrior, so my knowledge of MCUX is probably dangerous (?????). I'm not sure whether a 7-segment display is a peripheral device (peripherals.h and c) or a declaration for a number of pins (pin_mux.h and c), but that can be sorted out later.

 

 

0 Kudos
Reply

24 Views
luis_maravilla
NXP Employee
NXP Employee

Hi,

It could be that, as you define CA_LUT in peripherals.h both the main and peripherals.c call that file giving the duplicate error "multiple definition".

Could you help us try to add the declaration of CA_LUT only in peripherals.c instead of peripherals.h, and retry;

Do you have more declarations as this in peripherals.h? and they have the same error? If you have them please also move them to peripherals.c

Consider your 7 segments as an external peripheral device.

Let me know your findings

Best Regards

0 Kudos
Reply

64 Views
luis_maravilla
NXP Employee
NXP Employee

Hello,

Could you please share your peripherals.h file and peripherals.c? Or describe how did you add the declaration for CA_LUT?

Could you please share how did you use CA_LUT in main.c?

Kindly share all the files names in which do you have [#include "peripherals.h"], are those files headers included in main.c?

Best Regards, Luis

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2406174%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EDuplicate%20variable%20declarations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2406174%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20working%20on%20a%20new%20project%20using%20the%20LPC824%20board%20and%20the%20downloaded%20lpcxpresso824max_new_project.%20It%20built%2C%20downloaded%20and%20debugged%20without%20problems.%20Initially%20I%20am%20trying%20to%20implement%20a%203-digit%207-segment%20LED%20display.%20I%20added%20declarations%20in%20peripherals.h%20and%20an%20update%20routine%20in%20main.c.%20When%20I%20build%20I%20get%20two%20errors%20-%20duplicated%20variable%20declarations.%20If%20I%20comment%20them%20out%20I%20get%20a%20message%20%22undeclared%20variable%22.%20If%20I%20change%20the%20name%20of%20the%20variable%20I%20get%20the%20same%20duplication%20error.%20I%20have%20searched%20every%20source%20file%20in%20the%20project%20and%20cannot%20find%20any%20duplicates.%20One%20of%20the%20error%20messages%20is%3A%20-%3C%2FP%3E%3CP%3E%3CSPAN%3E%2FApplications%2FMCUXpressoIDE_25.6.136%2Fide%2Fplugins%2Fcom.nxp.mcuxpresso.tools.macosx_25.6.0.202501151204%2Ftools%2Fbin%2F..%2Flib%2Fgcc%2Farm-none-eabi%2F14.2.1%2F..%2F..%2F..%2F..%2Farm-none-eabi%2Fbin%2Fld%3A%20.%2Fsource%2Fperipherals.o%3A%2FUsers%2Fjulian%2FDocuments%2FMCUXpressoIDE_25.6.136%2Fworkspace%2Flpcxpresso824max_new_project%2FDebug%2F..%2Fsource%2Fperipherals.h%3A57%3A%20multiple%20definition%20of%20%60CA_LUT'%3B%20.%2Fsource%2Fmain.o%3A%2FUsers%2Fjulian%2FDocuments%2FMCUXpressoIDE_25.6.136%2Fworkspace%2Flpcxpresso824max_new_project%2FDebug%2F..%2Fsource%2Fperipherals.h%3A57%3A%20first%20defined%20here%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2406330%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Duplicate%20variable%20declarations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2406330%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3ECould%20you%20please%20share%20your%20peripherals.h%20file%20and%20peripherals.c%3F%20Or%20describe%20how%20did%20you%20add%20the%20declaration%20for%20CA_LUT%3F%3C%2FP%3E%0A%3CP%3ECould%20you%20please%20share%20how%20did%20you%20use%20CA_LUT%20in%20main.c%3F%3C%2FP%3E%0A%3CP%3EKindly%20share%20all%20the%20files%20names%20in%20which%20do%20you%20have%20%5B%23include%20%22peripherals.h%22%5D%2C%20are%20those%20files%20headers%20included%20in%20main.c%3F%3C%2FP%3E%0A%3CP%3EBest%20Regards%2C%20Luis%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2406686%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Duplicate%20variable%20declarations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2406686%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3EIt%20could%20be%20that%2C%20as%20you%20define%20CA_LUT%20in%20peripherals.h%20both%20the%20main%20and%20peripherals.c%20call%20that%20file%20giving%20the%20duplicate%20error%20%22multiple%20definition%22.%3C%2FP%3E%0A%3CP%3ECould%20you%20help%20us%20try%20to%20add%20the%20declaration%20of%20CA_LUT%20only%20in%20peripherals.c%20instead%20of%20peripherals.h%2C%20and%20retry%3B%3C%2FP%3E%0A%3CP%3EDo%20you%20have%20more%20declarations%20as%20this%20in%20peripherals.h%3F%20and%20they%20have%20the%20same%20error%3F%20If%20you%20have%20them%20please%20also%20move%20them%20to%20peripherals.c%3C%2FP%3E%0A%3CP%3EConsider%20your%207%20segments%20as%20an%20external%20peripheral%20device.%3C%2FP%3E%0A%3CP%3ELet%20me%20know%20your%20findings%3C%2FP%3E%0A%3CP%3EBest%20Regards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2406525%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Duplicate%20variable%20declarations%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2406525%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThis%20is%20the%20entry%20in%20peripherals.h%20for%20both%20errors%3C%2FP%3E%3CP%3E%2F%2F%20Lookup%20table%20for%20digits%200-9%20(0%20%3D%20ON%2C%201%20%3D%20OFF)%3CBR%20%2F%3Econst%20uint32_t%20CA_LUT%5B10%5D%20%3D%20%7B%3CBR%20%2F%3E%2F%2F0%3A%20A%2C%20B%2C%20C%2C%20D%2C%20E%2C%20F%20are%20ON%3B%20G%2C%20DP%20are%20OFF%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%201%3A%20B%2C%20C%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_B%3E%3C%2FSEG_B%3E%2F%2F%202%3A%20A%2C%20B%2C%20D%2C%20E%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%203%3A%20A%2C%20B%2C%20C%2C%20D%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%204%3A%20B%2C%20C%2C%20F%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_B%3E%3C%2FSEG_B%3E%2F%2F%205%3A%20A%2C%20C%2C%20D%2C%20F%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%206%3A%20A%2C%20C%2C%20D%2C%20E%2C%20F%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%207%3A%20A%2C%20B%2C%20C%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%208%3A%20All%20segments%20ON%20(A-G)%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%2F%2F%209%3A%20A%2C%20B%2C%20C%2C%20D%2C%20F%2C%20G%20are%20ON%3CBR%20%2F%3E~((1%26lt%3B%3CSEG_A%3E%3C%2FSEG_A%3E%7D%3B%3C%2FP%3E%3CP%3E%2F%2F%20Global%20variables%20holding%20the%20current%20numbers%20to%20be%20printed%20on%20Digits%201%2C%202%2C%20and%203%3CBR%20%2F%3Evolatile%20uint8_t%20display_buffer%5B3%5D%20%3D%20%7B1%2C%202%2C%203%7D%3B%20%2F%2F%20E.g.%2C%20displays%20%22123%22%3C%2FP%3E%3CP%3EBoth%20errors%20are%20used%20in%20main.c%20%3A-%3C%2FP%3E%3CP%3Euint8_t%20numeric_value%20%3D%20display_buffer%5Bcurrent_digit%5D%3B%3CBR%20%2F%3Euint32_t%20segment_pattern%20%3D%20CA_LUT%5Bnumeric_value%5D%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23include%20%22peripherals.h%22%20appears%20only%20in%20the%20following%20files%3A%20-%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Emain.c%2C%20peripherals.c%2C%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAS%20I%20mentioned%20I%20am%20coming%20over%20from%20CodeWarrior%2C%20so%20my%26nbsp%3B%3C%2FSPAN%3Eknowledge%20of%20MCUX%20is%20probably%20dangerous%20(%3F%3F%3F%3F%3F).%20I'm%20not%20sure%20whether%20a%207-segment%20display%20is%20a%20peripheral%20device%20(peripherals.h%20and%20c)%20or%20a%20declaration%20for%20a%20number%20of%20pins%20(pin_mux.h%20and%20c)%2C%20but%20that%20can%20be%20sorted%20out%20later.%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E