GCC problem - Questions

This is a discussion on GCC problem - Questions ; Hi all: I want to create a program with gcc. In this program must to include a header file is called sched.h,and it in the directory /usr/src/linux-2.6.5-1.358/include/linux. so,the head of the program is: #include and,to compile this program, type $ ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: GCC problem

  1. GCC problem

    Hi all:

    I want to create a program with gcc. In this program must to include a

    header file is called sched.h,and it in the directory

    /usr/src/linux-2.6.5-1.358/include/linux.

    so,the head of the program is: #include

    and,to compile this program, type

    $ gcc -c hello.c /usr/src/linux-2.6.5-1.358/include

    Could anyone tell me whether the practice above is correct?

    Thanks in advance
    Terence

  2. Re: GCC problem

    In comp.os.linux.development.apps terence@ms71.url.com.tw wrote:
    > I want to create a program with gcc. In this program must to include a
    > header file is called sched.h,and it in the directory
    > /usr/src/linux-2.6.5-1.358/include/linux.
    > so,the head of the program is: #include


    No normal program should need to include one of the kernel headers.
    Unless you have a very good reason to do so (and then you should
    know why and how this is done correctly) you're probably doing it
    for the wrong reasons.

    > and,to compile this program, type
    >
    > $ gcc -c hello.c /usr/src/linux-2.6.5-1.358/include
    >
    > Could anyone tell me whether the practice above is correct?


    No, it isn't. If you really need to include a kernel header you
    could use

    gcc -c hello.c -I/usr/src/linux-2.6.5-1.358/include

    But then you would typically instead use

    gcc -c hello.c -I/lib/modules/$(uname -r)/build/include

    and not hardcode the location of the kernel source directory into
    the command line. And if you want to compile a module you need also
    several other compiler options.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
    \__________________________ http://www.toerring.de

  3. Re: GCC problem

    Jens.Toerring@physik.fu-berlin.de wrote in message news:<2pcsshFjn4ihU1@uni-berlin.de>...
    > In comp.os.linux.development.apps terence@ms71.url.com.tw wrote:
    > > I want to create a program with gcc. In this program must to include a
    > > header file is called sched.h,and it in the directory
    > > /usr/src/linux-2.6.5-1.358/include/linux.
    > > so,the head of the program is: #include

    >
    > No normal program should need to include one of the kernel headers.
    > Unless you have a very good reason to do so (and then you should
    > know why and how this is done correctly) you're probably doing it
    > for the wrong reasons.
    >
    > > and,to compile this program, type
    > >
    > > $ gcc -c hello.c /usr/src/linux-2.6.5-1.358/include
    > >
    > > Could anyone tell me whether the practice above is correct?

    >
    > No, it isn't. If you really need to include a kernel header you
    > could use
    >
    > gcc -c hello.c -I/usr/src/linux-2.6.5-1.358/include
    >
    > But then you would typically instead use
    >
    > gcc -c hello.c -I/lib/modules/$(uname -r)/build/include
    >
    > and not hardcode the location of the kernel source directory into
    > the command line. And if you want to compile a module you need also
    > several other compiler options.
    > Regards, Jens



    Thank you for your answers.



    After I instead use

    gcc -c hello.c -I/lib/modules/$(uname -r)/build/include



    but output a lot of wrong information.



    In file included from
    /lib/modules/2.6.5-1.358/build/include/linux/sched.h:6,
    from hello.c:2:
    /lib/modules/2.6.5-1.358/build/include/linux/config.h:6:2: #error
    including kernel header in userspace; use the glibc headers instead!
    In file included from
    /lib/modules/2.6.5-1.358/build/include/linux/timex.h:186,
    from
    /lib/modules/2.6.5-1.358/build/include/linux/sched.h:11,
    from hello.c:2:
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:10: error: syntax
    error before "time_t"
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:10: warning: no
    semicolon at end of struct or union
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:12: error: syntax
    error before '}' token
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:16: error: syntax
    error before "time_t"
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:16: warning: no
    semicolon at end of struct or union
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:17: warning: data
    definition has no type or storage class
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:355: error: field
    `it_interval' has incomplete type
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:356: error: field
    `it_value' has incomplete type
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:360: error: field
    `it_interval' has incomplete type
    /lib/modules/2.6.5-1.358/build/include/linux/time.h:361: error: field
    `it_value' has incomplete type
    In file included from
    /lib/modules/2.6.5-1.358/build/include/linux/sched.h:11,
    from hello.c:2:
    /lib/modules/2.6.5-1.358/build/include/linux/timex.h:203: error: field
    `time' has incomplete type
    In file included from
    /lib/modules/2.6.5-1.358/build/include/linux/sched.h:12,
    from hello.c:2:
    /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:16: error:
    syntax error before "jiffies_64"
    /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:16: warning:
    data definition has no type or storage class
    /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:20: error:
    syntax error before "get_jiffies_64"
    /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:20: warning:
    data definition has no type or storage class...,etc.





    Could you tell me why this is?



    Thanks in advance

    Terence

  4. Re: GCC problem

    terence@ms71.url.com.tw wrote:
    > Jens.Toerring@physik.fu-berlin.de wrote in message news:<2pcsshFjn4ihU1@uni-berlin.de>...
    >
    >>In comp.os.linux.development.apps terence@ms71.url.com.tw wrote:
    >>
    >>> I want to create a program with gcc. In this program must to include a
    >>> header file is called sched.h,and it in the directory
    >>> /usr/src/linux-2.6.5-1.358/include/linux.
    >>> so,the head of the program is: #include

    >>
    >>No normal program should need to include one of the kernel headers.
    >>Unless you have a very good reason to do so (and then you should
    >>know why and how this is done correctly) you're probably doing it
    >>for the wrong reasons.
    >>


    (-- plenty of error messages clipped --)

    > /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:20: warning:
    > data definition has no type or storage class...,etc.


    > Could you tell me why this is?


    You cannot use the kernel internal headers such as sched.h in
    normal user-mode code. Even if you could compile the program,
    the results will very probably be wrong. Please read again
    the response from Jens Toerring, above.

    Would you please tell what you're attempting to achieve?

    If you'd like to read the scheduler data, a more appropriate
    way is to use the pseudo-files in the /proc filesystem.

    Tauno Voipio
    tauno voipio (at) iki fi


  5. Re: GCC problem

    Jens.Toerring@physik.fu-berlin.de wrote:

    > No, it isn't. If you really need to include a kernel header you
    > could use
    >
    > gcc -c hello.c -I/usr/src/linux-2.6.5-1.358/include


    .... actually, you SHOULD have the symlink "/usr/src/linux"
    that is set to point to the REAL location, which is
    /usr/src/linux-2.6.5-1.358 in this case, then you dont
    have to worry about using the -I switch
    --
    << http://michaeljtobler.homelinux.com/ >>
    Pure drivel tends to drive ordinary drivel off the TV screen.


  6. Re: GCC problem

    Tauno Voipio wrote in message news:...
    > terence@ms71.url.com.tw wrote:
    > > Jens.Toerring@physik.fu-berlin.de wrote in message news:<2pcsshFjn4ihU1@uni-berlin.de>...
    > >
    > >>In comp.os.linux.development.apps terence@ms71.url.com.tw wrote:
    > >>
    > >>> I want to create a program with gcc. In this program must to include a
    > >>> header file is called sched.h,and it in the directory
    > >>> /usr/src/linux-2.6.5-1.358/include/linux.
    > >>> so,the head of the program is: #include
    > >>
    > >>No normal program should need to include one of the kernel headers.
    > >>Unless you have a very good reason to do so (and then you should
    > >>know why and how this is done correctly) you're probably doing it
    > >>for the wrong reasons.
    > >>

    >
    > (-- plenty of error messages clipped --)
    >
    > > /lib/modules/2.6.5-1.358/build/include/linux/jiffies.h:20: warning:
    > > data definition has no type or storage class...,etc.

    >
    > > Could you tell me why this is?

    >
    > You cannot use the kernel internal headers such as sched.h in
    > normal user-mode code. Even if you could compile the program,
    > the results will very probably be wrong. Please read again
    > the response from Jens Toerring, above.


    I have understanded what you mean. Thans you.

    > Would you please tell what you're attempting to achieve?


    I want to design a procedure,and it can output a task_struct type structure

    of a process currently running on the CPU.

    > If you'd like to read the scheduler data, a more appropriate
    > way is to use the pseudo-files in the /proc filesystem.
    >


    How should I use pseudo-files?

    or,Where to refer to the usage?

    Thanks.

    Terence
    > Tauno Voipio
    > tauno voipio (at) iki fi


  7. Re: GCC problem

    terence@ms71.url.com.tw wrote:
    > Tauno Voipio wrote in message news:...
    >
    >>
    >>You cannot use the kernel internal headers such as sched.h in
    >>normal user-mode code. Even if you could compile the program,
    >>the results will very probably be wrong. Please read again
    >>the response from Jens Toerring, above.

    >
    >
    > I have understanded what you mean. Thans you.
    >
    >
    >>Would you please tell what you're attempting to achieve?

    >
    >
    > I want to design a procedure,and it can output a task_struct type structure
    > of a process currently running on the CPU.
    >


    You will always get the process data of the process containing
    your function - this cannot be interesting for a longer time.

    >>If you'd like to read the scheduler data, a more appropriate
    >>way is to use the pseudo-files in the /proc filesystem.
    >>

    >
    >
    > How should I use pseudo-files?


    Maybe the fast way is to get and read the sources of ps or top.

    For the user code, a pseudo-file is just a file that can be
    opened and read, as usual.

    You could start at the Linux source tree,
    Documentation/filesystems/proc.txt.

    Tauno Voipio
    tauno voipio (at) iki fi


  8. Re: GCC problem

    mjt wrote in message news:...
    > Jens.Toerring@physik.fu-berlin.de wrote:
    >
    > > No, it isn't. If you really need to include a kernel header you
    > > could use
    > >
    > > gcc -c hello.c -I/usr/src/linux-2.6.5-1.358/include

    >
    > ... actually, you SHOULD have the symlink "/usr/src/linux"
    > that is set to point to the REAL location, which is
    > /usr/src/linux-2.6.5-1.358 in this case, then you dont
    > have to worry about using the -I switch


    Thank for everybody's answer.

    And,I have a question wants to ask everybody.

    System call is a kind of method that is switched over from user mode
    to kernel mode by user's program.

    Could I via writing system call to direct use linux kernel code?

    If it is permitted,how should I create a system call on linux?

    Thanks in advance
    Terence

+ Reply to Thread