[질문]컴파일시 에러가 발생하는데 어떻게 해야 할지...???

ejooyong의 이미지

안녕하세요...
저는 리눅스 커널에 대해 공부하는 커널 초보생입니다... ^^

자료를 보며 실습을 하는데 에러가 나네요.
뭐가 문제인지 정말 답답하고 모르겠어서...

제가 실습해본 예제는,

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/malloc.h>
#include <asm/uaccss.h>

#define CHDRV_MAJOR 250

static ssize_t chdrv_read(struct file *filep, char *buf, size_t count, loff_t *ppos)
{
printk("chdrv_read called\n");
return(0);
}

static ssize_t chdrv_write(struct file *filep, const char *buf, size_t count, loff_t *ppos)
{
printk("chdrv_write called\n");
return(0);
}

static int chdrv_open(struct inode *inodep, struct file *filep)
{
if(MAJOR(inodep->i_rdev) != CHDRV_MAJOR)
return -1;
MOD_INC_USE_COUNT;
return 0;
}

static int chdrv_release(struct inode *inodep, struct file *filep)
{
if(MAJOR(inodep->i_rdev) != CHDRV_MAJOR)
return -1;
MOD_DEC_USE_COUNT;
return 0;
}

struct file_operations chdrv_fops =
{
NULL,
NULL,
chdrv_read,
chdrv_write,
NULL,
NULL,
NULL,
NULL,
chdrv_open,
NULL,
chdrv_release,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};

int init_module()
{
int ret_devreg;
ret_devreg = register_chrdev(CHDRV_MAJOR, "chdrv", &chdrv_fops);
if(ret_devreg<0) {
printk("chdrv -> MAJOR : %d char device driver not registered \n", CHDRV_MAJOR);
return ret_devreg;
}
return 0;
}

void cleanup_module()
{
unregister_chrdev(CHDRV_MAJOR, "chdrv");
}

gcc -D__KERNEL__ -D_LINUX -DMODULE -O2 -c chdrv.c

이렇게 컴파일을 하면,

warning: excess elements in struct initializer
warning: (near initialization for 'chdrv_fops')
.
. (이러한 warning이 file_operations 안의 내부 변수들 마다 나타납니다.)
.
storage size of 'chdrv_fops' isn't known

이러한 에러 메세지가 발생합니다.

또 궁금한 것이,
/usr/include/linux/fs.h 에는 file_operations 구조체가 선언되있지 않은데
/usr/src/linux-2.4.18-14/include/linux/fs.h 에는 선언되있습니다.

그럼 소스 코드에서
#include 하면
어느 헤더파일을 참조하는건가요?

제 시스템 환경은
P-4 2.4G
512M
Red Hat Linux 8.0(2.4.18-14)
VMware 4 beta
입니다.

여기저기 책들을 찾아보고 인터넷을 뒤져봐도
구현방법은 나왔는데 이러한 에러에 대한 얘기는 찾을 수가 없어서요.

긴 글이었네요... ^^;
답변 기다리겠습니다.
감사합니다.

judaspro의 이미지

:oops:

디바이스 드라이버 제작시 헤더파일은 /usr/include/가

아닌 /usr/src/linux/include에 있는 헤더파일을 참조합니다.

gcc -D__KERNEL__ _I/usr/src/linux버전/include/ -DMODULE -c -O2 source.c

링크가 안되있으면 그런 에러가 나올수 있거든요.

혹은 /dev 내에 nod를 생성했는지도 확인해 보세요.

허접한 넘이 답변을 했습니다. :cry:

좋은 하루되세요.

같은 지구에 살면서 차이가 나는건 왜일까???

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.