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

Build fails if libimobiledevice is installed with custom prefix #139

Closed
exioReed opened this issue Apr 28, 2020 · 9 comments
Closed

Build fails if libimobiledevice is installed with custom prefix #139

exioReed opened this issue Apr 28, 2020 · 9 comments

Comments

@exioReed
Copy link
Contributor

The build fails if libimobiledevice is installed with custom prefix for the following reasons:

  1. Typo in src/Makefile.am that results in missing CFLAGS for libimobiledevice.
$ make
make  all-recursive
make[1]: Entering directory '/opt/libimobiledevice/usbmuxd'
Making all in src
make[2]: Entering directory '/opt/libimobiledevice/usbmuxd/src'
  CC       usbmuxd-client.o
  CC       usbmuxd-device.o
  CC       usbmuxd-preflight.o
preflight.c:34:10: fatal error: libimobiledevice/libimobiledevice.h: No such file or directory
 #include <libimobiledevice/libimobiledevice.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
  1. Check for enum idevice_connection_type in configure.ac yields a false negative. As a result, HAVE_ENUM_IDEVICE_CONNECTION_TYPE is undefined and idevice_connection_type and will be redeclared in src/preflight.c:47.
$ make
make  all-recursive
make[1]: Entering directory '/opt/libimobiledevice/usbmuxd'
Making all in src
make[2]: Entering directory '/opt/libimobiledevice/usbmuxd/src'
  CC       usbmuxd-preflight.o
preflight.c:47:6: error: nested redefinition of ‘enum idevice_connection_type’
 enum idevice_connection_type {
      ^~~~~~~~~~~~~~~~~~~~~~~
preflight.c:47:6: error: redeclaration of ‘enum idevice_connection_type’
In file included from preflight.c:34:
/opt/libimobiledevice-1.2.1/include/libimobiledevice/libimobiledevice.h:63:6: note: originally defined here
 enum idevice_connection_type {
      ^~~~~~~~~~~~~~~~~~~~~~~
preflight.c:48:2: error: redeclaration of enumerator ‘CONNECTION_USBMUXD’
  CONNECTION_USBMUXD = 1,
  ^~~~~~~~~~~~~~~~~~
In file included from preflight.c:34:
/opt/libimobiledevice-1.2.1/include/libimobiledevice/libimobiledevice.h:64:2: note: previous definition of ‘CONNECTION_USBMUXD’ was here
  CONNECTION_USBMUXD = 1,
  ^~~~~~~~~~~~~~~~~~
preflight.c:49:2: error: redeclaration of enumerator ‘CONNECTION_NETWORK’
  CONNECTION_NETWORK
  ^~~~~~~~~~~~~~~~~~
In file included from preflight.c:34:
/opt/libimobiledevice-1.2.1/include/libimobiledevice/libimobiledevice.h:65:2: note: previous definition of ‘CONNECTION_NETWORK’ was here
  CONNECTION_NETWORK
  ^~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:497: usbmuxd-preflight.o] Error 1
make[2]: Leaving directory '/opt/libimobiledevice/usbmuxd/src'
make[1]: *** [Makefile:423: all-recursive] Error 1
make[1]: Leaving directory '/opt/libimobiledevice/usbmuxd'
make: *** [Makefile:355: all] Error 2
@exioReed
Copy link
Contributor Author

@nikias Could you provide directions on how to fix the second part. Essentially, is has to be ensured that AC_TRY_COMPILE succeeds with custom include directories for libimobiledevice (configure.ac:39).

@exioReed
Copy link
Contributor Author

Regarding part 2.

The documentation of AC_TRY_COMPILE states

This macro also uses CFLAGS or CXXFLAGS if either C or C++ is the currently selected language, as well as CPPFLAGS, when compiling.

For AC_TRY_COMPILE to be successful even if libimobiledevice is installed with custom prefix, the necessary include directories could be added as follows:

diff --git a/configure.ac b/configure.ac
index fb59203..6bac57c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,9 @@ if test "x$have_limd" = "xyes"; then
     AC_DEFINE(HAVE_LIBIMOBILEDEVICE, 1, [Define if you have libimobiledevice support])
     AC_SUBST(libimobiledevice_CFLAGS)
     AC_SUBST(libimobiledevice_LIBS)
+    # Cache CFLAGS
+    CACHE_CFLAGS_CHECK_ENUM_IDEVICE_CONNECTION_TYPE="$CFLAGS"
+    CFLAGS+=" $libimobiledevice_CFLAGS"
     AC_CACHE_CHECK(for enum idevice_connection_type, ac_cv_enum_idevice_connection_type,
       AC_TRY_COMPILE([
         #include <libimobiledevice/libimobiledevice.h>
@@ -44,6 +47,8 @@ if test "x$have_limd" = "xyes"; then
     if (test "$ac_cv_enum_idevice_connection_type" = "yes"); then
       AC_DEFINE(HAVE_ENUM_IDEVICE_CONNECTION_TYPE, 1, [Define if enum idevice_connection_type is available])
     fi
+    # Restore CFLAGS
+    CFLAGS="$CACHE_CFLAGS_CHECK_ENUM_IDEVICE_CONNECTION_TYPE"
   fi
 else
   if test "x$with_preflight" == "xyes"; then

Would this be an acceptable solution?

@nikias
Copy link
Member

nikias commented Apr 29, 2020

@exioReed well in this case you should be able to achieve the same thing by passing CFLAGS="-I/your/non-standard-prefix" to ./autogen.sh

@nikias
Copy link
Member

nikias commented Apr 29, 2020

But hmm. You are getting the non-standard prefix from pkg-config?

@exioReed
Copy link
Contributor Author

Sure. The PKG_CHECK_MODULES for libimobiledevice in configure.ac:21 succeeds and pkg-config yields

$ pkg-config --cflags libimobiledevice-1.0
-I/opt/libplist-2.1.0/include -I/opt/libusbmuxd-2.0.2/include -I/opt/imobiledevice-1.2.1/include

@nikias
Copy link
Member

nikias commented Apr 30, 2020

I pushed a fix.

@nikias nikias closed this as completed Apr 30, 2020
@voltagex
Copy link

I am still hitting this with the latest code from master.

@nikias
Copy link
Member

nikias commented May 15, 2021

What exactly happens?

@voltagex
Copy link

@nikias apologies, it was an issue with the include path - I got it working.

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

No branches or pull requests

3 participants