radvd icon indicating copy to clipboard operation
radvd copied to clipboard

cannot find strlcpy when libbsd is not install in system library dir

Open ysc3839 opened this issue 7 months ago • 8 comments

mkdir -p /opt/myprefix
tar xf libbsd-0.12.2.tar.xz
cd libbsd-0.12.2
./configure --prefix=/opt/myprefix
make && make install
export PKG_CONFIG_PATH=/opt/myprefix/lib/pkgconfig

cd ..
git clone https://github.com/radvd-project/radvd.git
cd radvd
./autogen.sh
./configure --prefix=/opt/myprefix

Result: configure: error: cannot find strlcpy - upgrade your libc or install libbsd

In config.log:

configure:4876: gcc -std=gnu99 -o conftest -g -O2   conftest.c -lbsd   >&5
/tmp/ccD6Zv1C.o: In function `main':
/root/radvd-test/radvd/conftest.c:24: undefined reference to `strlcpy'
collect2: error: ld returned 1 exit status
configure:4876: $? = 1

libbsd's library dir is not included in gcc command line.

My fix:

diff --git a/configure.ac b/configure.ac
index 1e764a5..7ee9b8d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,13 +107,13 @@ AC_CHECK_FUNCS(strlcpy, found_strlcpy=yes, found_strlcpy=no)
 if test "x$found_strlcpy" = xno; then
        dnl check libbsd for strlcpy
        PKG_CHECK_MODULES([BSD], [libbsd >= 0])
-       AC_SEARCH_LIBS(strlcpy, bsd,
-                                       [
-                                               found_bsd_strlcpy=yes
-                                               CFLAGS="$BSD_CFLAGS $CFLAGS"
-                                               LIBS="$BSD_LIBS $LIBS"
-                                       ],
-                                       found_bsd_strlcpy=no)
+       save_CFLAGS="$CFLAGS"; CFLAGS="$BSD_CFLAGS $CFLAGS"
+       save_LIBS="$LIBS"; LIBS="$BSD_LIBS $LIBS"
+       AC_SEARCH_LIBS(strlcpy, bsd, found_bsd_strlcpy=yes, [
+               found_bsd_strlcpy=no
+               CFLAGS="$save_CFLAGS"
+               LIBS="$save_LIBS"
+       ])
 fi

 if test "x$found_strlcpy" = xno && test "x$found_bsd_strlcpy" = xno; then

ysc3839 avatar Apr 11 '25 18:04 ysc3839

@ysc3839 what system are you running on? I want to add it to the test environment first to reproduce this

robbat2 avatar Apr 11 '25 22:04 robbat2

@robbat2 It's CentOS 7.

ysc3839 avatar Apr 12 '25 05:04 ysc3839

On Fri, Apr 11, 2025 at 10:12:53PM -0700, Richard Yu wrote:

It's CentOS 7.

There would finding the correct .rpm the better option.

IMNSHO is 'cannot find strlcpy when libbsd is not install in system library dir' an incomplete problem description.

I miss why not installed in system library.

Groeten Geert Stappers

Silence is hard to parse

stappersg avatar Apr 12 '25 08:04 stappersg

@stappersg I need to build a binary that not require other .so files. The libbsd is built as static library, and installed in my own build root dir.

ysc3839 avatar Apr 12 '25 14:04 ysc3839

@ysc3839 This feels like something isn't configured right on your system, but Centos7 has also been EOL for more than a year, so I cannot reproduce the bug. I tried w/ a Docker container based on rpmbuild/centos7:latest; but the CentOS mirrors are gone, so I couldn't build libbsd even, due to missing libmd.

--prefix only directs where files get installed by make install; and your commands for building libbsd mean both static & shared are build, along with radvd preferring the shared libraries.

If you are trying to get a static binary anyway, build it on a much newer system or docker container and copy to your target CentOS 7 box.

robbat2 avatar Apr 14 '25 05:04 robbat2

@robbat2 I will try other OS to see if this issue exists.

ysc3839 avatar Apr 14 '25 14:04 ysc3839

@robbat2 Same issue in Rocky Linux 9:

docker run -it --rm rockylinux:9 bash
yum install -y @'Development Tools' wget

mkdir -p /opt/myprefix

wget https://libbsd.freedesktop.org/releases/libbsd-0.12.2.tar.xz
tar xf libbsd-0.12.2.tar.xz
cd libbsd-0.12.2

# we don't need hash functions
# by disable these options, we don't need libmd
sed -i 's/abi_md5=yes/abi_md5=no/g' configure
sed -i 's/abi_arc4random=yes/abi_arc4random=no/g' configure

./configure --prefix=/opt/myprefix --disable-shared
make && make install

# libbsd produces a bad ld script when shared library disabled
# so remove it
# cat /opt/myprefix/lib/libbsd.so
# /* GNU ld script
#  * The MD5 functions are provided by the libmd library. */
# OUTPUT_FORMAT(elf64-x86-64)
# GROUP(/opt/myprefix/lib/ AS_NEEDED())
rm -f /opt/myprefix/lib/libbsd.so

cd ..

export PKG_CONFIG_PATH=/opt/myprefix/lib/pkgconfig

git clone https://github.com/radvd-project/radvd.git
cd radvd
./autogen.sh
./configure --prefix=/opt/myprefix

ysc3839 avatar Apr 14 '25 14:04 ysc3839

Why the --prefix=/opt/myprefix --disable-shared for libbsd?

stappersg avatar May 24 '25 05:05 stappersg