Thread: implicit declaration of function ‘get_current_dir_name’ ad is not corrected

  1. #1
    programmer hacker DevZero's Avatar
    Join Date
    Jul 2017
    Posts
    42

    Exclamation implicit declaration of function ‘get_current_dir_name’ ad is not corrected

    I had a big problem and I do not know how to solve it.
    I wrote at the beginning of the file:
    Code:
    #define __USE_GNU
    #include <unistd.h>
    In the file unistd.h I have here this line:
    Code:
    #ifdef	__USE_GNU
    /* Return a malloc'd string containing the current directory name.
       If the environment variable `PWD' is set, and its value is correct,
       that value is used.  */
    extern char *get_current_dir_name (void) __THROW;
    #endif
    In the file I have this code:
    Code:
    char *DName;
                     DName = get_current_dir_name();
    But at compilation I see here such warning:
    Code:
    ls.c: In function ‘printLine’:
    ls.c:268:18: warning: implicit declaration of function ‘get_current_dir_name’ [-Wimplicit-function-declaration]
                      DName = get_current_dir_name();
                      ^
    ls.c:268:24: warning: assignment makes pointer from integer without a cast
                      DName = get_current_dir_name();
                            ^

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,547
    How are you compiling your program? The get_current_dir_name() function is a compiler specific function that may not be available with certain compile flags.



    Jim

  3. #3
    programmer hacker DevZero's Avatar
    Join Date
    Jul 2017
    Posts
    42
    Quote Originally Posted by jimblumberg View Post
    How are you compiling your program? The get_current_dir_name() function is a compiler specific function that may not be available with certain compile flags.



    Jim
    Like this:
    Code:
    gcc -D_XOPEN_SOURCE=500 -std=c99 sds.o ls.c -o ls

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,547
    Using the "-std=c99" flag may disable the use of that function.

    What operating system are you using?

    Jim

  5. #5
    programmer hacker DevZero's Avatar
    Join Date
    Jul 2017
    Posts
    42
    Quote Originally Posted by jimblumberg View Post
    Using the "-std=c99" flag may disable the use of that function.

    What operating system are you using?

    Jim
    Code:
    ls.c: In function ‘getFileModificationTime’:
    ls.c:303:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
         for(int i=11; i<16; i++)
         ^
    And some more such mistakes.
    But even after I removed the key, I still have an error:
    Code:
    ls.c: In function ‘printLine’:
    ls.c:268:24: warning: assignment makes pointer from integer without a cast
                      DName = get_current_dir_name();
                            ^
    I using debian arme
    Code:
    Linux localhost 3.4.67 #1 SMP PREEMPT Tue Jun 16 11:20:16 CST 2015 armv7l GNU/Linux
    And gcc 4.9.2
    Last edited by DevZero; 07-08-2017 at 04:33 PM. Reason: Edit

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    Read the man page.
    You need to define _GNU_SOURCE, not __USE_GNU (whatever that is).

  7. #7
    programmer hacker DevZero's Avatar
    Join Date
    Jul 2017
    Posts
    42
    Quote Originally Posted by algorism View Post
    Read the man page.
    You need to define _GNU_SOURCE, not __USE_GNU (whatever that is).
    This define did not work for me, but now all of a sudden everything turned out. Problem solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implicit Declaration Of Function
    By nathanpc in forum C Programming
    Replies: 1
    Last Post: 01-26-2010, 08:46 PM
  2. implicit declaration of function?
    By BoneXXX in forum C Programming
    Replies: 2
    Last Post: 04-27-2007, 11:04 PM
  3. Implicit declaration of function ...???
    By soothsayer in forum C Programming
    Replies: 8
    Last Post: 08-07-2006, 06:49 AM
  4. Implicit declaration of function
    By soothsayer in forum C Programming
    Replies: 5
    Last Post: 02-28-2006, 02:56 PM
  5. implicit declaration of function 'int rand_r(...)'
    By Kirmie in forum C Programming
    Replies: 4
    Last Post: 10-24-2005, 11:40 PM

Tags for this Thread