Fix a linking issue in stubby when libbsd is present

When libbsd is found on the system during the configure, the result
of `pkg-config --cflags libbsd-overlay` is added to `CFLAGS`:

`-DLIBBSD_OVERLAY -isystem /usr/include/bsd`

The result of `pkg-config --libs libbsd-overlay` is added to `LIBS`,
but not to `STUBBY_LIBS`, which is used when linking stubby.

Because of the new `CFLAGS`, the preprocessor replaces the call to
`getopt()` in stubby.c with a call to `bsd_getop()`:

```
 #ifdef LIBBSD_OVERLAY
 #undef getopt
 #define getopt(argc, argv, optstr) bsd_getopt(argc, argv, optstr)
 #endif
```

But since `-lbsd` has not been added to `STUBBY_LIBS`, the linking of
stubby fails with an unresolved symbol:

```
../libtool --tag=CC --mode=link gcc -o stubby stubby.lo convert_yaml_to_json.lo gbuffer.lo -lyaml  libgetdns.la
libtool: link: gcc -o .libs/stubby .libs/stubby.o .libs/convert_yaml_to_json.o .libs/gbuffer.o  -lyaml ./.libs/libgetdns.so
/usr/bin/ld: .libs/stubby.o: undefined reference to symbol 'bsd_getopt@@LIBBSD_0.0'
/usr/lib/libbsd.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

Simply adding the result of `pkg-config --libs libbsd-overlay` to
`STUBBY_LIBS` in addition to `LIBS` fixes the issue.
This commit is contained in:
Remi Gacogne 2017-10-22 17:36:45 +02:00
parent cb6af78944
commit 8e12d86fc3
No known key found for this signature in database
GPG Key ID: A208ED4F8AF58446
1 changed files with 1 additions and 0 deletions

View File

@ -1270,6 +1270,7 @@ fi
# system implementation.
PKG_CHECK_MODULES([LIBBSD],[libbsd-overlay],[
LIBS="$LIBS $LIBBSD_LIBS"
STUBBY_LIBS="$STUBBY_LIBS $LIBBSD_LIBS"
CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
],[
AC_MSG_WARN([libbsd not found or usable; using embedded code instead])