libusb / libusb-compat-0.1

Working tree for libusb-compat-0.1
Other
38 stars 40 forks source link

libusb-config --libs is incorrect for static builds #15

Closed jameshilliard closed 2 years ago

jameshilliard commented 4 years ago

I see this issue of missing flags for the libusb-1.0 dependency was already fixed for pkg-config here but was not ported to libusb-config. This issue results in the flags needed to statically link against libusb-1.0 being missing and compilation fails for any applications getting their --libs flags from libusb-config.

mcuee commented 2 years ago

@jameshilliard Just wondering if you can create a pull requst for this issue. Thanks. BTW, I actually do not know how to fix this issue myself.

mcuee commented 2 years ago

@tormodvolden and @Youw Do you think this can be fixed or we should just close this one? I tend to think libusb-config can not do the job.

jameshilliard commented 2 years ago

BTW, I actually do not know how to fix this issue myself.

Yeah, I'm not really sure either.

Do you think this can be fixed or we should just close this one?

For static only builds of libusb/libusb-compat it should be able to set the correct flags, not sure about on mixed builds however as libusb-config doesn't seem to have a way to split static vs non-static flags. I hacked around the issue like this in buildroot.

mcuee commented 2 years ago

I think it is better to use pkg-config when possible. On the other end, even with pkg-config it may not be easy to do correctly for static build. I can see we still need some manual process.

Ref: some relevant discussions.

mcuee commented 2 years ago

libusb-config doesn't seem to have a way to split static vs non-static flags.

I agree. So I will close this one.

mcuee commented 2 years ago

For those who use cross-compile, you can take reference from the following to build static library with libusb-1.0 and libusb-compat-0.1. https://github.com/arduino/crossbuild/blob/main/deps/build_libs.sh https://github.com/arduino/crossbuild/pull/8/commits/9a0c6dfce444bf0d5434129903c9882561313e10

#!/bin/bash -ex

export PREFIX=/opt/lib/${CROSS_COMPILE}

if [ x$CROSS_COMPILER == x ]; then
CROSS_COMPILER=${CROSS_COMPILE}-gcc
CROSS_COMPILER_CXX=${CROSS_COMPILE}-g++
# AR=${CROSS_COMPILE}-ar
else
export CC=$CROSS_COMPILER
export CXX=$CROSS_COMPILER++
CROSS_COMPILER=$CC
CROSS_COMPILER_CXX=$CXX
fi
cd /opt/lib/libusb-1.0.26
export LIBUSB_DIR=`pwd`
./configure --prefix=${PREFIX} --with-pic --disable-udev --enable-static --disable-shared --host=${CROSS_COMPILE}
make distclean
./configure --prefix=${PREFIX} --with-pic --disable-udev --enable-static --disable-shared --host=${CROSS_COMPILE}
make -j$(nproc)
make install

export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
  export LIBUSB_1_0_CFLAGS=-I${PREFIX}/include/libusb-1.0
  export LIBUSB_1_0_LIBS="-L${PREFIX}/lib -lusb-1.0"
fi
cd /opt/lib/libusb-compat-0.1.7
export LIBUSB0_DIR=`pwd`
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix=${PREFIX} --enable-static --disable-shared --host=${CROSS_COMPILE}
make distclean
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix=${PREFIX} --enable-static --disable-shared --host=${CROSS_COMPILE}
make -j$(nproc)
make install
Youw commented 2 years ago

I'm not familiar with libusb-config tool to give more input on this one, but the fact that such tool exist surprises (and confuces) me a lot. It better be deprecated in favor of pkg-config since autotools is the primary build system for libusb.

mcuee commented 2 years ago

I will keep libusb-config for legacy projects which use libusb-config. But you are right it is better to use pkg-config.

Youw commented 2 years ago

How much different is it from pkg-config (I mean command line API/functionality)? Just an idea: would it be possible to implement libusb-config as a wrapper over pkg-config?

mcuee commented 2 years ago

@jameshilliard Just wondering why you still need to use libusb-config in https://github.com/buildroot/buildroot/commit/a3c9a41462a9a2a614978157ae4f2cbd26d66b21?

mcuee commented 2 years ago

How much different is it from pkg-config (I mean command line API/functionality)? Just an idea: would it be possible to implement libusb-config as a wrapper over pkg-config?

I tend to think there are legacy projects which does not require the pkg-config.

jameshilliard commented 2 years ago

Just wondering why you still need to use libusb-config in buildroot/buildroot@a3c9a41?

It's expected to be present by the apcupsd build system I think.