How to address multiple definition compiler error

993 views Asked by At

I am getting the following error messages, and I checked the file but can not figure out why or how to address the errors. Please help.

arch/arm/mach-msm/jtag-mm.o: In function `dbg_init_arch_data':
/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag-mm.c:279: multiple definition of `msm_jtag_save_cntr'
arch/arm/mach-msm/jtag.o:/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag.c:1085: first defined here
arch/arm/mach-msm/jtag-mm.o: In function `etm_init_arch_data':
/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag-mm.c:568: multiple definition of `msm_jtag_save_state'
arch/arm/mach-msm/jtag.o:/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag.c:1038: first defined here
arch/arm/mach-msm/jtag-mm.o: In function `msm_jtag_restore_state':
/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag-mm.c:585: multiple definition of `msm_jtag_restore_state'
arch/arm/mach-msm/jtag.o:/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag.c:1073: first defined here
arch/arm/mach-msm/jtag-mm.o: In function `dbg_init_arch_data':
/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag-mm.c:279: multiple definition of `msm_jtag_restore_cntr'
arch/arm/mach-msm/jtag.o:/home/sansari/WORKING_DIRECTORY/arch/arm/mach-msm/jtag.c:1085: first defined here
make[1]: *** [arch/arm/mach-msm/built-in.o] Error 1

I put a copy of jtag-mm.c at this link

Thanks. Here is jtag.c

After commenting out the jtag.h, and recompiling I get the following error message:

arch/arm/mach-msm/jtag-mm.c:790:2: error: implicit declaration of function 'msm_jtag_fuse_apps_access_disabled' [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors
make[1]: *** [arch/arm/mach-msm/jtag-mm.o] Error 1
make: *** [arch/arm/mach-msm] Error 2

@Peter - Thanks. I get what you are saying. Ok. let me try it. Never mind about the grep comment:-) I see it is not possible.

Update: Thanks. I can see what the issue is now. Now that I have posted the jtag.h, and jtag-mm.c, and jtag.c, you can perhaps validate what I think is the issue. As Peter mentioned, the variables are declared twice. Once by jtag.c and again by jtag-mm.c. For instance, I see the lines:

uint32_t msm_jtag_save_cntr[NR_CPUS];
uint32_t msm_jtag_restore_cntr[NR_CPUS];

in both files. But I tried to comment them out in one file, and I get an error since the variable is used in the same file in a function. What is the right way of handling this then? Can I declare it in the header file once, and just remove it from both source files? Or should I leave the deceleration in one source file, and include it in the other?

Here is a copy of jtag.h Thanks

1

There are 1 answers

5
Peter On BEST ANSWER

You haven't shown the jtag.h file, so it is only possible to speculate on what it is doing.

Since most of the errors disappear on "commenting out the jtag.h", the most likely explanation is that the header file has definitions, and one of the source files is #includeing that header file more than once (directly or - more likely - indirectly, due to other header files #includeing it). A common solution to that is to add include guards to the header file of the form

 #ifndef SOME_MACRO_CHOSEN_TO_BE_UNIQUE_TO_THE_HEADER
 #define SOME_MACRO_CHOSEN_TO_BE_UNIQUE_TO_THE_HEADER

   /*  the content of the header file

 #endif

You may also (after fixing the above, so the compiler stops choking on your code) get linker errors. That will result from multiple source files #includeing your header - hence the linker seeing symbols defined in multiple object files. The solution to that one will be to move the offending definitions (typically of either functions or static variables) from the header file to ONE (and only ONE) of the source files in your project.