Skip to content

OpenMP flags incorrectly applied to C files when using clang #1159

@krystophny

Description

@krystophny

Bug Description

When using the openmp = "*" dependency in fpm.toml, fpm applies OpenMP compiler flags (like -fopenmp) to all source files, including C files. This causes compilation failures when the default C compiler is clang, which doesn't support -fopenmp.

Reproduction Steps

  1. Create a project with both Fortran and C source files
  2. Add openmp = "*" to dependencies in fpm.toml
  3. Run fpm build on macOS (where clang is the default C compiler)

Expected Behavior

OpenMP flags should only be applied to Fortran files when using OpenMP dependency, or there should be a way to specify different compilers for C and Fortran files.

Actual Behavior

Build fails with:

clang: error: unsupported option '-fopenmp'

Environment

  • OS: macOS
  • fpm version: latest
  • Default C compiler: clang (doesn't support -fopenmp)
  • Default Fortran compiler: gfortran (supports -fopenmp)

Proposed Solutions

  1. Only apply OpenMP flags to Fortran source files
  2. Allow separate compiler configuration for C files (e.g., [build.c] section)
  3. Provide environment variable to override C compiler (e.g., FPM_CC)

This affects mixed-language projects that want to use OpenMP in Fortran while having simple C utility functions.

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