hello.c error - Hardware

This is a discussion on hello.c error - Hardware ; hey guys i am newbie and am trying to compile the famous helloworld program and i am using the following hello.c file and the make file also i have given and i am getting the following errors i am trying ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: hello.c error

  1. hello.c error

    hey guys i am newbie and am trying to compile the famous helloworld
    program and i am using the following hello.c file and the make file
    also i have given and i am getting the following errors i am trying
    from one week pls help

    hello.c
    **************************************

    #include
    #include

    static int hello_init(void) /* Loads a module in the kernel */
    {
    printk(KERN_ALERT"Hello kernel\n");
    return 0;

    }

    static void hello_exit(void) /* Removes module from kernel */
    {
    printk(KERN_ALERT"GoodBye Kernel\n");

    }

    module_init(hello_init);
    module_exit(hello_exit);

    makefile
    ****************************

    ifneq ($KERNELRELEASE),)

    obj-m :=hello.o

    else

    KERNELDIR := /lib/modules/$(shell uname -r)/build

    PWD := $(shell pwd)

    default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

    endif

    %make hello
    ********************************
    cc -c -o hello.o hello.c
    hello.c:2:24: error: linux/init.h: No such file or directory
    hello.c:3:26: error: linux/module.h: No such file or directory
    hello.c: In function 'hello_init':
    hello.c:7: error: 'KERN_ALERT' undeclared (first use in this function)
    hello.c:7: error: (Each undeclared identifier is reported only once
    hello.c:7: error: for each function it appears in.)
    hello.c:7: error: expected ')' before string constant
    hello.c: In function 'hello_exit':
    hello.c:13: error: 'KERN_ALERT' undeclared (first use in this
    function)
    hello.c:13: error: expected ')' before string constant
    hello.c: At top level:
    hello.c:16: warning: data definition has no type or storage class
    hello.c:16: warning: parameter names (without types) in function
    declaration
    hello.c:17: warning: data definition has no type or storage class
    hello.c:17: warning: parameter names (without types) in function
    declaration
    make: *** [hello.o] Error 1


  2. Re: hello.c error

    anganthia (angantia@gmail.com) writes:
    > hey guys i am newbie and am trying to compile the famous helloworld
    > program and i am using the following hello.c file and the make file
    > also i have given and i am getting the following errors i am trying
    > from one week pls help
    >

    You have a bigger problem. You've posted the same message three times,
    hours apart. That's bad enough. But after the first one or two, you
    did get a response, yet you either haven't seen it, or haven't looked.
    You have also posted that question three times in a newsgroup that
    is about computer hardware, more specifically about computer hardware
    as it relates to the Linux operating system. This is a programming
    question, and has nothing to do with hardware. And it's not even
    really a Linux related question, since C is a portable language.

    You might want to fix that problem first.

    One should point out that the point of "hello world" is to show a
    C program that is basically as simple as possible, so you can have
    immediate success and you will become familiar with the absolute
    minimum required for a C program.

    Anything more complicated is no longer "hello world". You should
    be starting with that simple program, and get it right first (obvious
    beginner errors would be mistyping keywords or not having enough
    brackets). Then you build on that, adding small things at a time,
    and compiling. Then if there are error messages, you can move back and
    figure out what went wrong. C can generate quite a few error
    messages, and some of them can be cryptic. The more you change
    at a time, the harder it is for you to determine what you've done
    to cause the error messages.

    This is nothing but a learning exercise. Once you've learned from
    it, then you are in a better position to deal with actually making
    decent programs in the language. You'll have worked out some of
    the connection between errors in the source code and those error
    messages, so you'll be in a better position to deal with more
    complicated programs (and the error messages that are generated
    when you make a mistake).

    Michael

  3. Re: hello.c error

    anganthia wrote:
    > hey guys i am newbie and am trying to compile the famous helloworld
    > program and i am using the following hello.c file and the make file
    > also i have given and i am getting the following errors i am trying
    > from one week pls help


    1) Posting 3 times in under 6 hours will not get you a faster response
    to your question. It could take several days to get an answer on Usenet.

    2) Your question is off-topic in this newsgroup. This is a hardware
    group (as the name implies), not a programming group. You need to ask
    in a group where the question is on-topic if you want a good answer.

    3) The source code you posted is for a *kernel module* not a user-space
    program. (You called it the "helloworld program", but it is not.) If
    you're trying to write a "Hello World" program, you're starting with the
    wrong source code.

+ Reply to Thread