简体   繁体   中英

Redefined symbol in multiple c code with #ifndef directive

I have a stupid problem and I don't see where it comes from. I took care of using #ifndef directive to make sure all my #include are not redefined. Sadly for three of them that's happening. Here my multiple files arch :

t_include.h

#ifndef T_INCLUDE_H_
#define T_INCLUDE_H_

/* Project specific dependencies*/
#include "utilities.h"
#include "fsp_function.h"

#include "ti/csl/csl_tsc.h"
#include "ti/csl/csl_cache.h"
#include "ti/csl/csl_cacheAux.h"

#include "ti_sp_complex_convolution_A_input1.h"
#include "ti_sp_complex_convolution_A_input2.h"
#include "to_sp_complex_convolution_A_output.h"

#endif /* T_INCLUDE_H_ */

t_function.h

#ifndef T_FUNCTION_H_
#define T_FUNCTION_H_

#include "t_include.h"

/*output vector*/
#define INPUT1A_LENGTH  5000
#define INPUT2A_LENGTH  2800
#define OUTPUTA_LENGTH  2202
extern FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

/*misc parameter*/
#define CPU_CLOCK_KHZ           1400000
#define CPU_CLOCK_MS            1/CPU_CLOCK_KHZ
#define FIR_NB_MACS             INPUT1A_LENGTH * OUTPUTA_LENGTH     /*   FIR algorithm complexity */
#define NB_OF_REP               10
#define UMA_L2CACHE_L1DCACHE    0

/* Project specific types */
typedef struct{
ect...

And now c file only include t_function.h :

t_function.c

/* Dependencies */
#include "t_function.h"
FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];
/* API  */
etc...

And t_main_function.c

/* dependencies */
#include "t_function.h"
void main(void) {
etc...

It should work but during linking here the errors comming :

<Linking>
error #10056: symbol "sp_complex_convolution_A_output" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
error #10056: symbol "sp_complex_convolution_A_input2" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
error #10056: symbol "sp_complex_convolution_A_input1" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"

error #10056: symbol "sp_complex_convolution_A_output_thales" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
>> Compilation failure
error #10010: errors encountered during linking; "CONVOLUTION_COMPLEX.out" not built

So the error only com from three symbol sp_complex_convolution_A_output, sp_complex_convolution_A_input1 and sp_complex_convolution_A_input2 Which are defined in their own .h which is also protected by #ifndef directives:

ti_sp_complex_convolution_A_input1.h

#ifndef __TI_SP_COMPLEX_CONVOLUTION_A_INPUT1_H_
#define __TI_SP_COMPLEX_CONVOLUTION_A_INPUT1_H_

FLOAT32 sp_complex_convolution_A_input1[2 * 2500] = {
etc... 

And the same for the other two...

So I really don't know why it is happening. Thx for helping

Definitions like:

FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

should go into a source file.

The header files should contain only declarations like:

extern FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

As a rule of thumb, do no put anything that allocates memory into header files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM