Question #6858   Submitted by Answiki on 10/10/2022 at 06:43:59 PM UTC

How to solve this error « undefined reference to 'strlcpy' » while compiling in C?

Answer   Submitted by Answiki on 10/10/2022 at 06:44:09 PM UTC

The error undefined reference to 'strlcpy' appears when compiling a C code using the library bsd/string.h. You need to link the  library as well as including the header. Add the -lbsd option to your command line while compiling:

gcc -o prog prog.c -lbsd

Note that the ordering is important. If you put the the source file after the -lbsd option, it may not work.

4 events in history
Answer by Answiki on 10/10/2022 at 06:44:09 PM

The error undefined reference to 'strlcpy' appears when compiling a C code using the library bsd/string.h. You need to link the  library as well as including the header. Add the -lbsd option to your command line while compiling:

gcc -o prog prog.c -lbsd

Note that the ordering is important. If you put the the source file after the -lbsd option, it may not work.

Question by Answiki 10/10/2022 at 06:43:59 PM
How to solve this error « undefined reference to 'strlcpy' » while compiling in C?
Answer by Answiki on 04/04/2022 at 04:23:58 PM

The error undefined reference to `strlcpy' appears when compiling a C code using the library bsd/string.h. You need to link the  library as well as including the header. Add the -lbsd option to your command line while compiling:

gcc -o prog prog.c -lbsd

Note that the ordering is important. If you put the the source file after the -lbsd option, it may not work.

Question by Answiki 04/04/2022 at 04:19:50 PM
How to solve this error « undefined reference to `strlcpy' » while compiling in C? replaced by #6858.
# ID Query URL Count

Icons proudly provided by Friconix.