Skip to content

Fix build failure in generate-accessors with -Werror set.#3079

Open
jimmunn wants to merge 1 commit intolinux-nvme:masterfrom
jimmunn:fix-generate-accessors-warning-in-build-file
Open

Fix build failure in generate-accessors with -Werror set.#3079
jimmunn wants to merge 1 commit intolinux-nvme:masterfrom
jimmunn:fix-generate-accessors-warning-in-build-file

Conversation

@jimmunn
Copy link

@jimmunn jimmunn commented Jan 29, 2026

The generate-accessors native executable uses asprintf() which requires _GNU_SOURCE. While the main project defines this flag via add_project_arguments(), native executables don't inherit these settings and need it explicitly defined.

This fix adds -D_GNU_SOURCE to the c_args for the generate_accessors executable, resolving the implicit declaration warning that becomes a build error when -Werror is enabled.

The generate-accessors native executable uses asprintf() which requires _GNU_SOURCE. While the main project defines this flag via add_project_arguments(), native executables don't inherit these settings and need it explicitly defined.

This fix adds -D_GNU_SOURCE to the c_args for the generate_accessors executable, resolving the implicit declaration warning that becomes a build error when -Werror is enabled.
@martin-belanger
Copy link

Hi @jimmunn - Just curious. You mention that native executables don't inherit settings set by add_project_arguments(). I was just reading the documentation on this function, and it seems that the arguments should apply to everything in this project. If not, there will be issues with other components. Should we use add_global_arguments() instead? However, the documentation for add_global_arguments() says: Usually you should use add_project_arguments() instead, because that works even when your project is used as a subproject.

Ref: https://mesonbuild.com/Reference-manual_functions.html#add_global_arguments

@jimmunn
Copy link
Author

jimmunn commented Jan 29, 2026

@martin-belanger , the reason the existing add_project_arguments does not apply to generate_accessors is because the add_project_arguments in the root meson.build file is does not set native: true.

add_project_arguments(
    [
        '-fomit-frame-pointer',
        '-D_GNU_SOURCE',
        '-include', nvme_config_h_path,
    ],
    language : 'c',
)

while generate_accessors sets native: true:

# Build the code generator tool
generate_accessors = executable(
    'generate-accessors',
    'generate-accessors.c',
    dependencies: [
        config_dep,
    ],
    native: true,
)

This is the only place in the project that uses native: true.

The documentation for add_global_arguments discourages its use, as you mentioned.

We could add another add_project_arguments call in the root meson.build with native: true instead of what I did. However, that separates the macro declaration from the one place that it is used. I think it is probably cleaner to keep it as I originally implemented it. What do you think?

@martin-belanger
Copy link

Agreed! I forgot about that native thing. This was the right fix. Thanks.

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 this pull request may close these issues.

2 participants