Skip to content

header error in static build on windows #51

@tihmstar

Description

@tihmstar

There is an issue with LIMD_GLUE_API definition in installed headers, which prevents static builds on windows.

In case of a static build, LIMD_GLUE_STATIC is defined in configure.ac

GLOBAL_CFLAGS+=" -DLIMD_GLUE_STATIC"

and passed to the environment as a compiler flag.

In the source files it is checked here:

#ifndef LIMD_GLUE_API
#ifdef LIMD_GLUE_STATIC
#define LIMD_GLUE_API
#elif defined(_WIN32)
#define LIMD_GLUE_API __declspec(dllimport)
#else
#define LIMD_GLUE_API
#endif
#endif

To decide how LIMD_GLUE_API should be defined if it doesn't already exist.

The problem however is, that LIMD_GLUE_STATIC is never defined outside of the buildenvironment of libimobiledevice-glue itself!
Which means that this case:

#ifdef LIMD_GLUE_STATIC
#define LIMD_GLUE_API
#elif defined(_WIN32)

Is never true when a 3rd party imports libimobiledevice-glue headers. As a result, on windows the headers will always define
#define LIMD_GLUE_API __declspec(dllimport)

which causes linker errors down the line when libimobiledevice-glue was built statically.


Checking whether libimobiledevice-glue was built statically cannot be done this way.
One solution would be to pre-process the header and statically resolve the condition before installing the header.

One example of this can be seen here:
https://github.com/tihmstar/img4tool/blob/d082f71dbf06f5d325140c14b47a0a214908f57c/include/img4tool/img4tool.hpp.in#L19-L21

Note: This problem also applies to other libimobiledevice projects which define _APIs in a similar matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions