简体   繁体   English

使用#ifndef 指令在多个 c 代码中重新定义符号

[英]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.我负责使用#ifndef 指令来确保我所有的#include 都没有被重新定义。 Sadly for three of them that's happening.可悲的是,他们三个正在发生这种情况。 Here my multiple files arch :这是我的多个文件 arch :

t_include.h 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 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 :现在 c 文件只包含 t_function.h :

t_function.c t_function.c

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

And t_main_function.c和 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:因此,错误仅来自三个符号 sp_complex_convolution_A_output、sp_complex_convolution_A_input1 和 sp_complex_convolution_A_input2,它们定义在它们自己的 .h 中,也受 #ifndef 指令保护:

ti_sp_complex_convolution_A_input1.h 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.根据经验,不要将任何分配内存的内容放入头文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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