gphoto / gphoto2

The gphoto2 commandline tool for accessing and controlling digital cameras.
GNU General Public License v2.0
718 stars 116 forks source link

Build failure with stricter C compilers (e.g. GCC 14) #615

Open thesamesam opened 11 months ago

thesamesam commented 11 months ago

Describe the bug

Modern C compilers are becoming stricter with a variety of changes over the last year or so.

GCC 14 in particular (to be released in ~April 2024) fails to build gphoto2-2.2.58 like:

gphoto2-cmd-config.c: In function ‘set_config’:
gphoto2-cmd-config.c:74:42: error: passing argument 4 of ‘newCDKDialog’ from incompatible pointer type [-Wincompatible-pointer-types]
   74 |                                          msg, 4, buttons, 2,
      |                                          ^~~
      |                                          |
      |                                          const char **
In file included from /usr/include/cdk.h:40,
                 from gphoto2-cmd-config.c:36:
/usr/include/cdk/dialog.h:90:17: note: expected ‘char **’ but argument is of type ‘const char **’
   90 |                 CDK_CSTRING2    /* message */,
      |                 ^~~~~~~~~~~~
gphoto2-cmd-config.c:74:50: error: passing argument 6 of ‘newCDKDialog’ from incompatible pointer type [-Wincompatible-pointer-types]
   74 |                                          msg, 4, buttons, 2,
      |                                                  ^~~~~~~
      |                                                  |
      |                                                  const char **
/usr/include/cdk/dialog.h:92:17: note: expected ‘char **’ but argument is of type ‘const char **’
   92 |                 CDK_CSTRING2    /* buttons */,
      |                 ^~~~~~~~~~~~
gphoto2-cmd-config.c: In function ‘show_section’:
gphoto2-cmd-config.c:127:32: error: passing argument 8 of ‘newCDKScroll’ from incompatible pointer type [-Wincompatible-pointer-types]
  127 |                                (const char**)items, count, NUMBERS, A_REVERSE, TRUE, FALSE);
      |                                ^~~~~~~~~~~~~~~~~~~
      |                                |
      |                                const char **
/usr/include/cdk/scroll.h:82:17: note: expected ‘char **’ but argument is of type ‘const char **’
   82 |                 CDK_CSTRING2    /* itemList */,
      |                 ^~~~~~~~~~~~
gphoto2-cmd-config.c: In function ‘show_radio’:
gphoto2-cmd-config.c:321:53: error: passing argument 6 of ‘newCDKItemlist’ from incompatible pointer type [-Wincompatible-pointer-types]
  321 |                                title, _("Value: "), (const char**)items, count,
      |                                                     ^~~~~~~~~~~~~~~~~~~
      |                                                     |
      |                                                     const char **
/usr/include/cdk/itemlist.h:86:17: note: expected ‘char **’ but argument is of type ‘const char **’
   86 |                 CDK_CSTRING2    /* itemlist */,
      |                 ^~~~~~~~~~~~
gphoto2-cmd-config.c: In function ‘show_toggle’:
gphoto2-cmd-config.c:378:32: error: passing argument 6 of ‘newCDKItemlist’ from incompatible pointer type [-Wincompatible-pointer-types]
  378 |                                info, 2, 1 - value, TRUE, FALSE);
      |                                ^~~~
      |                                |
      |                                const char **
/usr/include/cdk/itemlist.h:86:17: note: expected ‘char **’ but argument is of type ‘const char **’
   86 |                 CDK_CSTRING2    /* itemlist */,
      |                 ^~~~~~~~~~~~
make[2]: *** [Makefile:797: gphoto2-gphoto2-cmd-config.o] Error 1

Originally reported downstream in Gentoo at https://bugs.gentoo.org/919279.

Name the camera N/A

libgphoto2 and gphoto2 version libgphoto2-2.5.1, gphoto2-2.5.28

To Reproduce Steps to reproduce the behavior: This can be emulated with -Werror=incompatible-pointer-types -Werror=implicit -Werror=int-conversion on an older GCC or Clang.

Similar to https://github.com/gphoto/libgphoto2/issues/941.

msmeissn commented 11 months ago

This is an issue with CDK I would say.

cdk-devel-5.0.20230201-1.1.x86_64 on openSUSE tumbleweed: /usr/include/cdk/cdk_config.h:#define CDK_CSTRING2 CDK_CONST char CDK_CONST

In older CDK 4.9.13 it was char**, so CDK changes its prototypes.

I could add a configure check, but perhaps you can update cdk to version 5?

msmeissn commented 11 months ago

or we enforce use of cdk >= 5

thesamesam commented 11 months ago

huh, interestingly, we only have these versions..

5.0.20210324-r2, 5.0.20221025, 5.0.20230201

let me see if a configure test got confused..

msmeissn commented 11 months ago

check cdk_config.h too on your side.

thesamesam commented 11 months ago

ok, my cdk_config.h has:

[...]
#define CDK_CONST /*nothing*/
#define CDK_CSTRING CDK_CONST char *
#define CDK_CSTRING2 CDK_CONST char * CDK_CONST *
[...]

configure for gphoto2 says:

checking for cdk/cdk.h... no
checking for cdk.h... yes
checking for cdk5-config... /usr/bin/cdk5-config
checking for newCDKFScale in -lcdk... no

config.h says for gphoto2 says:

/* whether we have old CDK */
#define HAVE_CDK_20010421 1

looking more..

thesamesam commented 11 months ago

jwakely kindly tested for me on Fedora and shared their cdk_config.h as well.

Diffing the two:

$ diff -ruN /tmp/good /usr/include/cdk/cdk_config.h
--- /tmp/good   2023-12-06 15:48:25.136119401 +0000
+++ /usr/include/cdk/cdk_config.h   2023-12-06 12:43:56.528424776 +0000
@@ -7,7 +7,7 @@
 #define CDK_CONFIG_H 1

-#define CDK_CONST const
+#define CDK_CONST /*nothing*/
 #define CDK_CSTRING CDK_CONST char *
 #define CDK_CSTRING2 CDK_CONST char * CDK_CONST *
 #define CDK_PATCHDATE 20230201
@@ -44,6 +44,7 @@
 #define CDK_HAVE_TYPE_CHTYPE 1
 #define CDK_HAVE_UNCTRL_H 1
 #define CDK_HAVE_UNISTD_H 1
+#define CDK_HAVE_WCHAR_H 1
 #define CDK_MIXEDCASE_FILENAMES 1
 #define CDK_NCURSES 1
 #define CDK_PACKAGE "cdk"

It turns out Fedora (and openSUSE) builds cdk with --enable-const. If I use that, then everything is fine.

So, this is PEBKAC to an extent, and I'll fix our package for cdk in Gentoo now. Up to you if you think configure for gphoto2 should check for this. Thank you for the help!

msmeissn commented 11 months ago

FWIW its not a super state of cdk being API flexible this way.

msmeissn commented 11 months ago

i replaced "const" by CDK_CONST in the affected places now, this might help with both variants.