繁体   English   中英

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

[英]Redefined symbol in multiple c code with #ifndef directive

我有一个愚蠢的问题,我不知道它来自哪里。 我负责使用#ifndef 指令来确保我所有的#include 都没有被重新定义。 可悲的是,他们三个正在发生这种情况。 这是我的多个文件 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...

现在 c 文件只包含 t_function.h :

t_function.c

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

和 t_main_function.c

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

它应该可以工作,但在此处链接期间出现错误:

<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

因此,错误仅来自三个符号 sp_complex_convolution_A_output、sp_complex_convolution_A_input1 和 sp_complex_convolution_A_input2,它们定义在它们自己的 .h 中,也受 #ifndef 指令保护:

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... 

另外两个也一样...

所以我真的不知道为什么会这样。 感谢帮助

定义如:

FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

应该进入源文件。

头文件应该只包含如下声明:

extern FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

根据经验,不要将任何分配内存的内容放入头文件。

暂无
暂无

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

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