10

Gcc throws an error when I try to call the functions strlcpy or strlcat in a C file:

error : implicit declaration of strlcpy
error : implicit declaration of strlcat

In what library can I find those functions, and their man page? I included string.h but it doesn't change anything. I'm running Linux Mint 17.2 and gcc 4.8.4

3
  • 1
    man strlcpy will display their man page. If you're having problems with your code, you need to post the code, post the compiler command line, and do it on Stack Overflow since programming questions are off-topic here. Sep 20, 2015 at 23:50
  • 2
    strlcpy() and similar are available in libc on most UNIX variants. Linux is an exception as a former glibc maintainer did not like them even though he was not able to explain why or to point to a better concept. Software that ports to Linux usually implements own versions of these functions.
    – schily
    Sep 21, 2015 at 11:11
  • @schily note that this is no longer true: sourceware.org/git/…
    – Étienne
    Jan 17 at 15:49

1 Answer 1

15

On Ubuntu, Mint, and relatives, strlcpy and strlcat are available in the libbsd-dev package. Run

sudo apt-get install libbsd-dev

This will install the libraries, header files, and man pages.

To use the functions from C code, add the line

#include <bsd/string.h>

to your files, and add -lbsd , or the more portable $(pkg-config --libs libbsd) , to your gcc command line to link the library.

1
  • Note that the functions are now available in glibc 2.38 and above: sourceware.org/git/… (which is available e.g. in Ubuntu 23.10)
    – Étienne
    Jan 17 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .