Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jameshilliard opened this issue May 3, 2020 · 12 comments
Closed

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

jameshilliard opened this issue May 3, 2020 · 12 comments
Labels
build related to build scripts

Comments

@jameshilliard
Copy link

jameshilliard commented May 3, 2020

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
Copy link
Member

mcuee commented Oct 29, 2022

@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
Copy link
Member

mcuee commented Oct 31, 2022

@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
Copy link
Author

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
Copy link
Member

mcuee commented Nov 1, 2022

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
Copy link
Member

mcuee commented Nov 1, 2022

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 mcuee closed this as completed Nov 1, 2022
@mcuee
Copy link
Member

mcuee commented Nov 1, 2022

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
arduino/crossbuild@9a0c6df

#!/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
Copy link
Member

Youw commented Nov 1, 2022

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
Copy link
Member

mcuee commented Nov 3, 2022

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

@Youw
Copy link
Member

Youw commented Nov 3, 2022

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
Copy link
Member

mcuee commented Nov 3, 2022

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

@mcuee
Copy link
Member

mcuee commented Nov 3, 2022

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build related to build scripts
Projects
None yet
Development

No branches or pull requests

3 participants