在头文件&中定义var的重复符号多重包容保护 [英] Duplicate symbols with var defined in header & multiple inclusion protection

查看:225
本文介绍了在头文件&中定义var的重复符号多重包容保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #ifndef __FT_OPP_H__ 
#define __FT_OPP_H__
t_opp gl_opptab [] = {{ - ,& ft_sub},\
{+,& ft_add}, \
{*,& ft_mul},\
{/,& ft_div},\
{%,&ft_mod},\
{,& ft_usage}};
#endif / * __FT_OPP_H__ * /

我别无选择,只能使用此文件来定义gl_opptab数组(它是学校练习的一部分,我应该使用这个文件)。



但是,我不断收到以下消息GCC编译后:


重复符号_gl_opptab in:
/var/folders/zz/zyxvpxvq6csfxvn_n0000hvc00046v/T//ccrPWPyP.o
/var/folders/zz/zyxvpxvq6csfxvn_n0000hvc00046v/T//cc2JUzLs.o ld:1架构x86_64的重复符号collect2:ld返回1退出
状态make: * [ft_advanced_do -op]错误1


我试过只在一个文件中使用 extern t_opp * gl_opptab 在另一个.c文件中。但它似乎并不奏效。



我怎么能这样做?

解决方案

div> extern t_opp * gl_opptab 与标题中定义的结构数组不同。在另一个.c文件中尝试 extern t_opp gl_opptab []; 。当然另一个.c文件需要知道 t_opp 是什么,所以至少还有一个头文件需要包含在另一个.c文件中。


I have this header file (called ft_opp.h), that I'm trying to #include in two different .c files:

#ifndef __FT_OPP_H__
# define __FT_OPP_H__
t_opp gl_opptab[] = {{"-", &ft_sub}, \
{"+", &ft_add}, \
{"*", &ft_mul}, \
{"/", &ft_div}, \
{"%", &ft_mod}, \
{"", &ft_usage}};
#endif /* __FT_OPP_H__ */

I have no choice but to use this file unchanged to define the gl_opptab array (it's part of an exercise at school and I'm supposed to use this file as is).

However, I keep getting the following message from GCC after compilation:

duplicate symbol _gl_opptab in: /var/folders/zz/zyxvpxvq6csfxvn_n0000hvc00046v/T//ccrPWPyP.o /var/folders/zz/zyxvpxvq6csfxvn_n0000hvc00046v/T//cc2JUzLs.o ld: 1 duplicate symbol for architecture x86_64 collect2: ld returned 1 exit status make: * [ft_advanced_do-op] Error 1

I have tried including it in only one file and using extern t_opp* gl_opptab in the other .c file. But it doesn't seem to work.

How could I do that?

解决方案

extern t_opp* gl_opptab is not the same as the array of structs defined in the header. Try extern t_opp gl_opptab[]; in the other .c file. Of course the other .c file will need to know what a t_opp is, so there's at least one more header that'll need inclusion in the other .c file.

这篇关于在头文件&中定义var的重复符号多重包容保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆