How to resolve compiler warning 'implicit declaration of function memset'

前端 未结 5 941
终归单人心
终归单人心 2021-02-01 02:45

My c code uses \'memset\' and \'close\'. And I have added:

#include 
#include 
#include 

But I sti

相关标签:
5条回答
  • 2021-02-01 03:11

    Old question but I had similar issue and I solved it by adding

    extern void* memset(void*, int, size_t);
    

    or just

    extern void* memset();
    

    at the top of translation unit ( *.c file ).

    0 讨论(0)
  • 2021-02-01 03:15

    Try to add next define at start of your .c file:

    #define _GNU_SOURCE
    

    It helped me with pipe2 function.

    0 讨论(0)
  • 2021-02-01 03:21

    A good way to findout what header file you are missing:

     man <section> <function call>
    

    To find out the section use:

    apropos <function call>
    

    Example:

     man 3 memset
     man 2 send
    

    Edit in response to James Morris:

    • Section | Description
    • 1 General commands
    • 2 System calls
    • 3 C library functions
    • 4 Special files (usually devices, those found in /dev) and drivers
    • 5 File formats and conventions
    • 6 Games and screensavers
    • 7 Miscellanea
    • 8 System administration commands and daemons

    Source: Wikipedia Man Page

    0 讨论(0)
  • 2021-02-01 03:25

    You need:

    #include <string.h> /* memset */
    #include <unistd.h> /* close */
    

    in your code.

    References: POSIX for close, the C standard for memset.

    0 讨论(0)
  • 2021-02-01 03:25

    memset requires you to import the header string.h file. So just add the following header

    #include <string.h>
    ...
    
    0 讨论(0)
提交回复
热议问题