android - 内核 c 多重函数定义错误

标签 android c compiler-errors linux-kernel

我目前正在尝试为我的 android 设备编译内核 不幸的是,我遇到了这个编译错误并坚持了下来

编译器说:

drivers/dpram/built-in.o:(.bss+0x2815c): multiple definition of `pm_dev'
drivers/net/built-in.o:(.bss+0x1ac4): first defined here

在 drivers/dpram.c 中我有:

struct device *pm_dev;

    pm_dev = device_create(sec_class, NULL, 0, NULL, "pm");
    if(IS_ERR(pm_dev))
        pr_err("Failed to create device(pm)!\n");
    if(device_create_file(pm_dev, &dev_attr_info) < 0)
        pr_err("Failed to create device file(%s)!\n", dev_attr_info.attr.name);
    if(device_create_file(pm_dev, &dev_attr_power_down) < 0)
        pr_err("Failed to create device file(%s)!\n", dev_attr_power_down.attr.name);

在 drivers/net/wireless/bcmdhd/bcmsdh_linux.c 中我有:

struct device *pm_dev;

    if (!device_init_wakeup(dev, 1))
        pm_dev = dev;

    if (pm_dev) {
        device_init_wakeup(pm_dev, 0);
        pm_dev = NULL;
    }

我目前正在尝试弄清楚,但我还做不到

最佳答案

错误是因为

struct device *pm_dev;

是C语言中的一个定义。它定义了一个指向结构device的指针,它的名字是pm_dev。不允许多次定义变量,因此您应该在所有其他源文件中将 pm_dev 声明为 extern,但只在您实际定义变量的文件中声明它。

声明:

extern struct device *pm_dev;

单一定义:

struct device *pm_dev;

关于android - 内核 c 多重函数定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372030/

相关文章:

Android RelativeLayout 添加layout_alignParentBottom 将布局推送到屏幕底部

c - 合并字符串 C 中的字符排序

c++ - tbb::cache_aligned_allocator:使用 __m128i 获取 "request for member...which is of non-class type"。用户错误或错误?

java - 为什么我会收到此错误 : E/ERROR: The executeQuery method must return a result set. ?

android - 如何在 Android - API 8 中执行 chmod?

android - 是否需要关闭使用 window.openDatabase 打开的数据库?

Android Camera 2 API 在 Nougat 7.1 上出现闪光灯问题

c - C语言中的字符串输入问题

c++ - extern 内联函数被引用但未定义

c++ - 错误编译 Unresolved external 错误