linux c 报错 multiple definition of ‘xxx’ 解决方法

错误:

方法一

在test.c中定义

//test.c
......

struct pdesc const cameractrl_params[] = {
{PT_STRI_, 0,  1, OFFSET(cameractrl, homecmd), "homecmd", 32, 0, NULL, NULL},
    {PT_STRI_, 0,  1, OFFSET(cameractrl, zoomctrl), "zoomctrl", 32, 0, NULL, NULL},
    {PT_STRI_, 0,  1, OFFSET(cameractrl, focusctrl), "focusctrl", 32, 0, NULL, NULL},
    {PT_STRI_, 0,  1, OFFSET(cameractrl, aperturectrl), "aperturectrl", 32, 0, NULL, NULL},
    {PT_NULL_, 0,  0, 0, "", 0, 0, NULL, NULL} /* PT_NULL means tail of struct pdesc array */
};

......

在test.h中定义

//test.h
#ifndef _TEST_H_
#define _TEST_H_

......

extern struct pdesc const cameractrl_params[];

......

#endif

方法二

 在test.h头文件中

变量前加static关键字

发布了57 篇原创文章 · 获赞 574 · 访问量 499万+

猜你喜欢

转载自blog.csdn.net/whatday/article/details/104598924