libmtp / libmtp

A library to access MTP (Media Transfer Protocol) Devices.
https://sf.net/projects/libmtp
GNU Lesser General Public License v2.1
157 stars 68 forks source link

Unable to compile using MSYS/Mingw-64 #20

Open BryanWallin opened 5 years ago

BryanWallin commented 5 years ago

@msmeissn (correct me if you're not the right contact),

I'm attemtping to create a .dll using MSYS2 and MINGW64, and I'm running into an issue revolving around the missing langinfo.h header. It looks like the config.h file is generated properly as HAVE_LANGINFO_H is not defined. However, this leads to problems when compiling with make, as certain parameters like cd_locale_to_ucs2 and cd_ucs2_to_locale are defined within an #ifdef (ptp.h, line 2810):

#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
    /* PTP: iconv converters */
    iconv_t cd_locale_to_ucs2;
    iconv_t cd_ucs2_to_locale;
#endif

Then, when I try to use make after the ./configure command finishes, I get these errors because there aren't any #ifdef statements in libmtp.c:

libmtp.c: In function 'LIBMTP_Open_Raw_Device_Uncached':
libmtp.c:1879:17: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_locale_to_ucs2'
   current_params->cd_locale_to_ucs2 = iconv_open("UTF-16LE", "UTF-8");
                 ^~
libmtp.c:1879:39: warning: implicit declaration of function 'iconv_open'; did you mean '_open'? [-Wimplicit-function-declaration]
   current_params->cd_locale_to_ucs2 = iconv_open("UTF-16LE", "UTF-8");
                                       ^~~~~~~~~~
                                       _open
libmtp.c:1880:17: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_ucs2_to_locale'
   current_params->cd_ucs2_to_locale = iconv_open("UTF-8", "UTF-16LE");
                 ^~
libmtp.c:1882:20: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_locale_to_ucs2'
   if(current_params->cd_locale_to_ucs2 == (iconv_t) -1 ||
                    ^~
libmtp.c:1882:44: error: 'iconv_t' undeclared (first use in this function); did you mean 'ino_t'?
   if(current_params->cd_locale_to_ucs2 == (iconv_t) -1 ||
                                            ^~~~~~~
                                            ino_t
libmtp.c:1882:44: note: each undeclared identifier is reported only once for each function it appears in
libmtp.c:1883:20: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_ucs2_to_locale'
      current_params->cd_ucs2_to_locale == (iconv_t) -1) {
                    ^~
libmtp.c: In function 'LIBMTP_Release_Device':
libmtp.c:2431:3: warning: implicit declaration of function 'iconv_close'; did you mean '_findclose'? [-Wimplicit-function-declaration]
   iconv_close(params->cd_locale_to_ucs2);
   ^~~~~~~~~~~
   _findclose
libmtp.c:2431:21: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_locale_to_ucs2'
   iconv_close(params->cd_locale_to_ucs2);
                     ^~
libmtp.c:2432:21: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_ucs2_to_locale'
   iconv_close(params->cd_ucs2_to_locale);

I think this is an issue that needs to be solved in the libmtp library, or if it cannot be, it needs to be made clear that this cannot compile on MINGW/MSYS2. Is there a suggestion of something I could do to fix the issue in the meantime?

ibinshoid commented 5 years ago

I had the same problem. after your commit "handle missing langinfo.h (windows) " i get this messages from mingw32-configure && make on OpenSuse 15.0 :

libtool: compile:  i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/i686-w64-mingw32/sys-root/mingw/include/libusb-1.0 -O2 -g -pipe -Wall -fexceptions --param=ssp-buffer-size=4 -mms-bitfields -Wall -Wmissing-prototypes -MT libmtp_la-libmtp.lo -MD -MP -MF .deps/libmtp_la-libmtp.Tpo -c libmtp.c -o libmtp_la-libmtp.o >/dev/null 2>&1
mv -f .deps/libmtp_la-libmtp.Tpo .deps/libmtp_la-libmtp.Plo
/bin/sh ../libtool  --tag=CC   --mode=compile i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I..    -I/usr/i686-w64-mingw32/sys-root/mingw/include/libusb-1.0 -O2 -g -pipe -Wall -fexceptions --param=ssp-buffer-size=4 -mms-bitfields -Wall -Wmissing-prototypes -MT libmtp_la-unicode.lo -MD -MP -MF .deps/libmtp_la-unicode.Tpo -c -o libmtp_la-unicode.lo `test -f 'unicode.c' || echo './'`unicode.c
libtool: compile:  i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/i686-w64-mingw32/sys-root/mingw/include/libusb-1.0 -O2 -g -pipe -Wall -fexceptions --param=ssp-buffer-size=4 -mms-bitfields -Wall -Wmissing-prototypes -MT libmtp_la-unicode.lo -MD -MP -MF .deps/libmtp_la-unicode.Tpo -c unicode.c  -DDLL_EXPORT -DPIC -o .libs/libmtp_la-unicode.o
unicode.c: In function 'utf16_to_utf8':
unicode.c:91:23: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_ucs2_to_locale'
   nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax);
                       ^~
unicode.c:91:44: warning: passing argument 2 of 'iconv' from incompatible pointer type [-Wincompatible-pointer-types]
   nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax);
                                            ^~~~~~~~
In file included from unicode.c:37:
/usr/i686-w64-mingw32/sys-root/mingw/include/iconv.h:17:48: note: expected 'const char **' but argument is of type 'char **'
 size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
unicode.c: In function 'utf8_to_utf16':
unicode.c:126:23: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_locale_to_ucs2'
   nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax);
                       ^~
unicode.c:126:44: warning: passing argument 2 of 'iconv' from incompatible pointer type [-Wincompatible-pointer-types]
   nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax);
                                            ^~~~~~~~
In file included from unicode.c:37:
/usr/i686-w64-mingw32/sys-root/mingw/include/iconv.h:17:48: note: expected 'const char **' but argument is of type 'char **'
 size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
make[2]: *** [Makefile:524: libmtp_la-unicode.lo] Fehler 1
make[2]: Verzeichnis „/home/andreas/SRC/libmtp-master/src“ wird verlassen
make[1]: *** [Makefile:526: all-recursive] Fehler 1
make[1]: Verzeichnis „/home/andreas/SRC/libmtp-master“ wird verlassen
make: *** [Makefile:389: all] Fehler 2
gniezen commented 4 years ago

I'm getting the compile error on unicode.c when using MSYS2/MINGW64:

unicode.c: In function 'utf16_to_utf8':
unicode.c:91:23: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_ucs2_to_locale'
   91 |   nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax);
      |                       ^~
unicode.c: In function 'utf8_to_utf16':
unicode.c:126:23: error: 'PTPParams' {aka 'struct _PTPParams'} has no member named 'cd_locale_to_ucs2'
  126 |   nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax);

Is there any way to compile libmtp under Windows, as based on README.windows.txt MSYS/MINGW is the way to go?