简体   繁体   English

linux内核源代码中的错误?

[英]error in kernel source code of linux?

I modified the kernel source code r8169.c and calculating the timestamp as below: 我修改了内核源代码r8169.c并计算timestamp如下:

s64 a;
EXPORT_SYMBOL(a);
a = time();

I did not add the original timestamp function call 我没有添加原始时间戳函数调用

I am using the variable a in another source file in kernel: ip_input.c 我在内核中的另一个源文件中使用变量a: ip_input.c

extern s64 a;

s64 b,c;
b= time();
c = b-a; 

I receive this error: 我收到此错误:

 ERROR: undefined reference to a 

How to solve it? 怎么解决?

From the incomplete source code, I guess that 从不完整的源代码,我猜

s64 a;
EXPORT_SYMBOL(a);
a = time();

is inside a function and therefore, a cannot be exported, because it is local to that function. 是在函数内部,因此, a不能出口,因为它是局部的功能。

To use a outside of this module, you must define it with file scope, eg 要使用此模块a外部,必须使用文件范围定义它,例如

s64 a;
EXPORT_SYMBOL(a);

void some_function()
{
    a = time();
}

This allows the symbol for a to be exported and then used in another module. 这允许导出a的符号,然后在另一个模块中使用。

r8169.c is a module, whereas ip_input.c is in the main kernel. r8169.c是一个模块,而ip_input.c在主内核中。 The main kernel cannot import symbols from a module. 主内核无法从模块导入符号。 The fix for this is to declare your variable within ip_input.c, and import it from r8169.c. 解决此问题的方法是在ip_input.c中声明您的变量,并从r8169.c导入它。 You also have to use file scope as Olaf mentioned. 您还必须使用Olaf提到的文件范围。

ip_input.c: ip_input.c:

s64 a, b, c;
EXPORT_SYMBOL(a);

void someFunc() {
   b=time();
   c=b-a;
}

r8169.c: r8169.c:

extern s64 a;

void someFunc() {
    a=time();
}

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

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