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 failure with stricter C compilers (e.g. GCC 14) #615

Open
thesamesam opened this issue Dec 6, 2023 · 8 comments
Open

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

thesamesam opened this issue Dec 6, 2023 · 8 comments

Comments

@thesamesam
Copy link

thesamesam commented Dec 6, 2023

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 gphoto/libgphoto2#941.

@msmeissn
Copy link
Contributor

msmeissn commented Dec 6, 2023

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

msmeissn commented Dec 6, 2023

or we enforce use of cdk >= 5

@thesamesam
Copy link
Author

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

msmeissn commented Dec 6, 2023

check cdk_config.h too on your side.

@thesamesam
Copy link
Author

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

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!

gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Dec 6, 2023
I don't understand why, in the year 2023, this is optional or at the very least
not default-on, but whatever.

It turns out that Fedora and openSUSE at least, probably many others, are building
cdk with --enable-const which is why this only showed up on Gentoo. We do the same
--enable-const dance for ncurses so I suppose I should've known.

Enable it for parity given it should be fine to go in this direction anyway.

Bug: gphoto/gphoto2#615
Closes: https://bugs.gentoo.org/919279
Signed-off-by: Sam James <sam@gentoo.org>
@msmeissn
Copy link
Contributor

msmeissn commented Dec 6, 2023

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

@msmeissn
Copy link
Contributor

msmeissn commented Dec 6, 2023

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

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

2 participants