Skip to content

libgphoto2+gphoto2 builds fail looking for gphoto2/gphoto2-foo.h include file #717

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

Closed
ndim opened this issue Sep 9, 2021 · 4 comments · Fixed by #764
Closed

libgphoto2+gphoto2 builds fail looking for gphoto2/gphoto2-foo.h include file #717

ndim opened this issue Sep 9, 2021 · 4 comments · Fixed by #764
Assignees

Comments

@ndim
Copy link
Member

ndim commented Sep 9, 2021

Describe the bug

When there are no gphoto2/gphoto2-*.h include files in the C preprocessor's default include path, building gphoto2 fails when trying to #include a gphoto2/gphoto2-foo.h include file:

In file included from actions.c:45:
./actions.h:24:10: fatal error: 'gphoto2/gphoto2-camera.h' file not found
#include <gphoto2/gphoto2-camera.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

The reason is that both libgphoto2.pc and libgphoto2_port.pc both contain

Cflags: -I${includedir}/gphoto2

but the gphoto2 source code uses

#include <gphoto2/gphoto2-camera.h>

which we have declared the standard way of including libgphoto2 headers.

We have removed the symlink which used to link ${includedir}/gphoto2/gphoto2 to ${includedir}/gphoto2 in #452 after #444, and that symlink used to hack this to work.

libgphoto2 and gphoto2 version

To Reproduce

On a system which does not have any gphoto2 headers installed in the C preprocessor path,

cd
cd libgphoto2
./configure --prefix=$HOME/.local
make all
make install

cd
cd gphoto2
./configure --prefix=$HOME/.local PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig
make all
@ndim
Copy link
Member Author

ndim commented Sep 9, 2021

The "proper" way to fix this would be to change the libgphoto2.pc and libgphoto2_port.pc files to both read

Cflags: -I${includedir}

instead of

Cflags: -I${includedir}/gphoto2

We should have done that in #452 already.

Anybody disagreeing?

@ndim ndim self-assigned this Sep 9, 2021
@msmeissn
Copy link
Contributor

hmm. kamera uses <gphoto2.h> , needs adaption then.
digikam has also a single <gphoto2.h> include I think.

our tooling (gphoto2, gtkam) uses gphoto2/gphoto2.h already.
python bindings seem to actually work around the above already.
darktable uses gphoto2/gphoto2.h already
wine is ok
... cant check the external tools ...

but i think the change is okay, some packages might need to adjust

@ndim
Copy link
Member Author

ndim commented Sep 15, 2021

Or we change to Cflags: -I${includedir}/gphoto-2.5 in both libgphoto2_port.pc and libgphoto2.pc, but change the installation location of the header files from /usr/include/gphoto2/gphoto2-camera.h to /usr/include/gphoto-2.5/gphoto2/gphoto2-camera.h, similar to /usr/include/gtk-3.0/gtk/gtkwindow.h.

@ndim
Copy link
Member Author

ndim commented Jan 21, 2022

Or we can have both, basically going back to the /usr/include/gphoto2 directory days with the ln -s . gphoto2 symlink.

Cflags: -I${includedir}/gphoto2 -I${includedir}

Anyway, I would really like to fix this in order to be able to build gphoto2 against a libgphoto2 I have just built and installed.

Let's consider the not uncommon case of the Linux distro providing a libgphoto2-devel package which ships the include files in /usr/include/gphoto2/*.h, and we compile our own libgphoto2 to $HOME/.local and want to compile a libgphoto2 client like e.g. the gphoto2 CLI interface using the include headers from $HOME/.local and linking against the library from $HOME/.local. We achieve this by setting PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig before running the libgphoto2 client's configure script or equivalent which runs pkg-config to determine compile and link flags.

As it stands, we have

Cflags: -I${includedir}/gphoto2

which leads to

source include directive libgphoto2-devel installed using gphoto2.h header file build result
#include <gphoto2.h> yes $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}/gphoto2) good
#include <gphoto2.h> no $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}/gphoto2) good
#include <gphoto2/gphoto2.h> yes /usr/include/gphoto2/gphoto2.h (via default path /usr/include, as there is no $HOME/.local/include/gphoto2/gphoto2/gphoto2.h) silently uses wrong headers broken
#include <gphoto2/gphoto2.h> no there is no $HOME/.local/include/gphoto2/gphoto2/gphoto2.h or /usr/include/gphoto2/gphoto2.h fail

So our preferred source way of including libgphoto2 header files never actually does what is expected!

If we change the *.pc files to

Cflags: -I${includedir}

the possibilities for a build are

source include directive libgphoto2-devel installed using gphoto2.h header file build result
#include <gphoto2.h> yes looking for non-existing $HOME/.local/include/gphoto2.h and /usr/include/gphoto2.h fail
#include <gphoto2.h> no looking for non-existing $HOME/.local/include/gphoto2.h and /usr/include/gphoto2.h fail
#include <gphoto2/gphoto2.h> yes $HOME/.local/include/gphoto2/gphoto2.h (via -I$HOME/.local/include, searched before default /usr/include) good
#include <gphoto2/gphoto2.h> no $HOME/.local/include/gphoto2/gphoto2.h (via -I$HOME/.local/include, searched before default /usr/include) which has no gphoto2 headers anyway) good

If we change the *.pc files to

Cflags: -I${includedir} -I${includedir}/gphoto2

the possibilities for a build are

source include directive libgphoto2-devel installed using gphoto2.h header file build result
#include <gphoto2.h> yes $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}/gphoto2) good
#include <gphoto2.h> no $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}/gphoto2) good
#include <gphoto2/gphoto2.h> yes $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}) good
#include <gphoto2/gphoto2.h> no $HOME/.local/include/gphoto2/gphoto2.h (via -I${includedir}) good

I prefer build failures over silently building something unexpected. This leaves us the last two options, because both of them never produce a build using wrong headers:

  • -I${includedir} breaks builds of all versions of libgphoto2 clients before changing from #include <*.h> to #include <gphoto2/*.h>
  • -I${includedir} -I${includedir}/gphoto2 produces correct builds with both #include <*.h> and #include <gphoto2/*.h>. Gives libgphoto2 clients time to switch to #include <gphoto2/*.h>. Requires communicating with those clients, and waiting a few years until the pre-switch clients with the old API are mostly out of circulation. Or we just keep the double -I indefinitely.

So this boils down to how stable do we want our API to be. The #include <...> lines are definitely part of the API in addition to function signatures and types, so I guess the double -I option would be preferable.

ndim added a commit to ndim/libgphoto2 that referenced this issue Jan 21, 2022
In the *.pc files, use a C preprocessor include path both with
and without the gphoto2/ path component:

    Cflags: -I${includedir} -I${includedir}/gphoto2

This allows both the preferred way to include gphoto2 headers

    #include <gphoto2/gphoto2.h>
    #include <gphoto2/gphoto2-camera.h>

and also the early 2000s legacy way (still in use by kamera and others)

    #include <gphoto2.h>
    #include <gphoto2-camera.h>

to produce builds with the libgphoto2 headers actually corresponding
to the *.pc files in use.

Any other option for the *.pc file Cflags either produces
unintended build failures or builds which use the wrong header
files (the `-I${includedir}/gphoto2` option), or breaks the
`#include <...>` part of the libgphoto2 API from the early 2000s
still in use by kamera and others (the `-I${includedir}` option).

For details, see gphoto#717 and
gphoto#717 (comment)

Fixes: gphoto#717
ndim added a commit to ndim/libgphoto2 that referenced this issue Jan 21, 2022
In the *.pc files, use a C preprocessor include path both with
and without the gphoto2/ path component:

    Cflags: -I${includedir} -I${includedir}/gphoto2

This allows both the preferred way to include gphoto2 headers

    #include <gphoto2/gphoto2.h>
    #include <gphoto2/gphoto2-camera.h>

and also the early 2000s legacy way (still in use by kamera and others)

    #include <gphoto2.h>
    #include <gphoto2-camera.h>

to produce builds with the libgphoto2 headers actually corresponding
to the *.pc files in use.

Any other option for the *.pc file Cflags either produces
unintended build failures or builds which use the wrong header
files (the `-I${includedir}/gphoto2` option), or breaks the
`#include <...>` part of the libgphoto2 API from the early 2000s
still in use by kamera and others (the `-I${includedir}` option).

For details, see gphoto#717 and
gphoto#717 (comment)

Fixes: gphoto#717
ndim added a commit to ndim/libgphoto2 that referenced this issue Jan 21, 2022
In the *.pc files, use a C preprocessor include path both with
and without the gphoto2/ path component:

    Cflags: -I${includedir} -I${includedir}/gphoto2

This allows both the preferred way to include gphoto2 headers

    #include <gphoto2/gphoto2.h>
    #include <gphoto2/gphoto2-camera.h>

and also the early 2000s legacy way (still in use by kamera and others)

    #include <gphoto2.h>
    #include <gphoto2-camera.h>

to produce builds with the libgphoto2 headers actually corresponding
to the *.pc files in use.

Any other option for the *.pc file Cflags either produces
unintended build failures or builds which use the wrong header
files (the `-I${includedir}/gphoto2` option), or breaks the
`#include <...>` part of the libgphoto2 API from the early 2000s
still in use by kamera and others (the `-I${includedir}` option).

For details, see gphoto#717 and
gphoto#717 (comment)

Fixes: gphoto#717
@ndim ndim closed this as completed in bd5aec3 Jan 23, 2022
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

Successfully merging a pull request may close this issue.

2 participants