简体   繁体   English

为用户模式Linux编译程序

[英]Compiling a program for user mode Linux

I've just implemented a "pseudo" device driver and want to test it. 我刚刚实现了“伪”设备驱动程序,并想对其进行测试。 What can I do as a test is just: 我可以做的测试只是:

echo "something"> /dev/mydev
cat /dev/mydev

My driver supports more advanced functionality and I implemented a test program to test these functionaries. 我的驱动程序支持更高级的功能,我实现了一个测试程序来测试这些功能。 However I'm not able to run it on UML (Error: Floating point exception). 但是我无法在UML上运行它(错误:浮点异常)。 I believe there is a "special" way of compiling user programs for UML? 我相信有一种“特殊的”方式为UML编译用户程序吗?

Could you please give a starting point for this? 您能为此提供一个起点吗? How should I compile the test program? 我应该如何编译测试程序?

ps Testing program is very simple and above error is not caused by the bug in the program. ps测试程序非常简单,上述错误并非由程序中的错误引起。 pps For compiling the module I had ready Makefile, so it was easy :) pps用于编译模块,我已经准备好Makefile,所以很容易:)

Thanks in advance. 提前致谢。

EDIT: Both host and UML kernels are of same version 2.6.35 编辑:主机和UML内核都具有相同的版本2.6.35

EDIT: I believe I need to show kernel source directory, plus some compiler options, also something like ARCH=um? 编辑:我相信我需要显示内核源目录,再加上一些编译器选项,还类似于ARCH = um?

EDIT: Currently I'm compiling without any options. 编辑:目前,我正在编译,没有任何选项。 gcc test.c. gcc测试 Even the "Hello world" program is not working on the UML. 甚至“ Hello world”程序也无法在UML上运行。 Maybe i've to change something on UML compilation? 也许我必须对UML编译进行一些更改?

The solution for the problem is found (thanks to my classmates and professor): 找到了解决问题的方法(感谢我的同学和教授):

the glibc versions of the compile environment should match with UML. 编译环境的glibc版本应与UML匹配。 So compiling --static option solves the problem. 因此,编译--static选项可以解决该问题。

If you want to read/write from/to your device, you have to implement, and then use on your program, at least the system calls open() , read() , write() and close() , like any other device on you Linux. 如果要从设备读取/写入设备,则必须实现并在程序上使用,至少像其他设备一样,系统调用open()read()write()close() 。在您的Linux上。 For the example you gave, your program would be something like this (syntax might contain some errors): 对于您给出的示例,您的程序将如下所示(语法可能包含一些错误):

char* string = "something";
char* result = (char*)malloc(sizeof(char) * strlen(string) + 1);

int fd = open("/dev/mydev", O_RDWR);

write(fd, "something", strlen(string));

read(fd, result, strlen(string));
printf("result = %s\n", result);

close(fd);

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

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