Find the answer to your Linux question:
Results 1 to 6 of 6
Hello friends! I am developing using a sytem calls and macros. When I use TASK_RUNNING and compile I get this error message: Code: /home/jesus/pruebas/c/proceso1.c:8: error: ‘TASK_RUNNING’ undeclared (first use in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104

    TASK_RUNNING undeclared


    Hello friends! I am developing using a sytem calls and macros. When I use TASK_RUNNING and compile I get this error message:

    Code:
    /home/jesus/pruebas/c/proceso1.c:8: error: ‘TASK_RUNNING’ undeclared (first use in this function)
    /home/jesus/pruebas/c/proceso1.c:8: error: (Each undeclared identifier is reported only once
    /home/jesus/pruebas/c/proceso1.c:8: error: for each function it appears in.)
    I put the simply code:

    Code:
    #include <stdio.h>
    #include <linux/sched.h>
    
    int main()
    {
    	int a=TASK_RUNNING;
    	set_current_state(a);
    
    
    }
    I have searched in the Web, and I only found solutions saying for include <linux/sched.h>, but I doesn't work!!
    Thank you very much!!

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Sorry it took so long to get to this - I've been away for the holidays.

    The macro TASK_RUNNING is defined in your Linux kernel development include directory, usually /usr/src/linux/include/linux/sched.h. By default, the compiler will take what it finds in /usr/include/linux/sched.h for your #include <linux/sched.h>, and TASK_RUNNING is not defined there. You need to add the -I /usr/src/linux/include to your compile command and/or CFLAGS in your Makefile.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104

    TASK_RUNNING undeclared

    Many thanks Rubberman. but i still get the same error. Maybe my command line isn't correct. I put it

    Code:
     gcc -l /usr/src/linux-source-2.6.32/include/linux/ proceso1.c -o proceso1

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Quote Originally Posted by jesusitoLinux View Post
    Many thanks Rubberman. but i still get the same error. Maybe my command line isn't correct. I put it

    Code:
     gcc -l /usr/src/linux-source-2.6.32/include/linux/ proceso1.c -o proceso1
    Try:
    Code:
     gcc -I /usr/src/linux-source-2.6.32/include proceso1.c -o proceso1
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Linux Newbie
    Join Date
    Nov 2009
    Posts
    104
    I'm still getting the same error..... I've probed this line
    Code:
     gcc -I /usr/src/linux-source-2.6.32/include proceso1.c -o proceso1
    and this one

    Code:
    gcc -I /usr/src/linux-source-2.6.32/include/linux proceso1.c -o proceso1
    The output of the last one is even worse.

    Code:
    In file included from /usr/include/stdio.h:34,
                     from proceso.c:1:
    /usr/src/linux-source-2.6.32/include/linux/stddef.h:4:28: error: linux/compiler.h: No existe el archivo o directorio
    In file included from /usr/include/stdio.h:75,
                     from proceso.c:1:
    /usr/include/libio.h:332: error: expected specifier-qualifier-list before ‘size_t’
    /usr/include/libio.h:364: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/libio.h:373: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/libio.h:495: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
    In file included from proceso.c:1:
    /usr/include/stdio.h:296: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:302: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:314: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:321: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:363: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:365: error: format string argument not a string type
    /usr/include/stdio.h:367: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:639: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:642: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:652: error: expected declaration specifiers or ‘...’ before ‘size_t’
    /usr/include/stdio.h:682: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
    /usr/include/stdio.h:688: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
    /usr/include/stdio.h:710: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread_unlocked’
    /usr/include/stdio.h:712: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite_unlocked’
    proceso.c: In function ‘main’:
    proceso.c:6: error: ‘TASK_RUNNING’ undeclared (first use in this function)
    proceso.c:6: error: (Each undeclared identifier is reported only once
    proceso.c:6: error: for each function it appears in.)

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    I think you are trying to mix user-space and kernel-space headers in the same code. Not a good idea, but if you have to, then take out the -I directive and specify the full path to your source/include directory with the #include directives in your code. IE, instead of

    #include <linux/stddef.h>

    use

    #include </usr/src/linux-source-2.6.32/include/linux/stddef.h>

    instead. Not guaranteeing that this weill work, since it will likely include other kernel headers, leaving you still in the lurch...

    So, if what you REALLY need are the system call ID's, then I suggest you simply cut/paste them from the kernel header into your code, or your own header file.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •