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

时间:2017-10-23 14:22:48

标签: c include directive defined ifndef

我有一个愚蠢的问题,我不知道它来自哪里。我负责使用#ifndef指令来确保我的所有#include都没有重新定义。可悲的是,其中有三个正在发生。这里我的多个文件拱起:

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

其他两个人也一样......

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

1 个答案:

答案 0 :(得分:1)

定义如:

do {

    printf("How many numbers do u want: ");
    scanf_s("%i", &a);
    printf("od: ");
    scanf_s("%i", &b);
    printf("do: ");
    scanf_s("%i", &c);

    h = c + 1; 
    f = b - h; 
    //printf("%i %i %i\n", h, f);
    for (d; d < a; d++) {
        printf("%i ", b + rand() % f);
    }
    printf("\n");
    printf("Restart? T- yes");
    scanf_s("%c", &e);
} while (e == 't' || e == 'T');
_getch();
return 0;
}

应该进入源文件。

头文件应仅包含如下声明:

FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];

根据经验,不要将任何内存分配到头文件中。