Skip to content

Conversation

@MilanSkocic
Copy link

Issue #1205 highlighted that the fPIC, necessary for shared libraries, was not passed for C sources either with profile release or debug.

For CFLAGS, a hot fix was applied i.e. the flag is hard-coded 353ec23.
Equivalent function of fpm_compiler.F90/get_<debug/release>_compile_flags should be implemented for pulling default flags for C sources as it is the case for Fortran sources.

The FFLAGS are hard-coded both profiles (release and debug) in feature_collection/default_<release/debug>_feature(). However, it might better to pull from default compile flags defined in fpm_compiler.F90/get_<release/debug>_compile_flag (cb7d15c)

Use get_debug_compile_flags and get_release_compile_flags for pulling
the default flags instead of hard-coding them in
features_collection.f90.
A better solution would be to define getters for CFLAGS i.e.
get_debug_compile_c_flags and get_release_compile_c_flags.
Use them to pull the default flags for C sources.
Copy link
Member

@perazz perazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this PR @MilanSkocic -

Please generalize default_variant instead:

  1. add character(*), optional, intent(in) :: c_flags, cxx_flags arguments
  2. set them if present
  3. customize the compiler/OS default variants for both debug and release by adding the PIC flag (may not be the same on all platforms)

@MilanSkocic
Copy link
Author

MilanSkocic commented Nov 15, 2025

That's what I wanted to do by adding optional arguments.
I'll try to find all the adequate fPIC equivalents for the corresponding platforms.

Imports not needed for now. They will be necessary if a solution by
using functions defined in the module `fpm_compiler.F90` is decided.
All variants, except those for OS_WINDOWS, will accept the -fPIC flag
for C/C++ sources.

A more complete set of flags for C/C++ sources was added for the gcc
compiler.

For the other compilers, additional work might be needed to define the
correct flags mathcing those passed for Fortran sources.
All variants, except those for OS_WINDOWS, will accept the -fPIC flag
for C/C++ sources.

A more complete set of flags for C/C++ sources was added for the gcc
compiler.

For the other compilers, additional work might be needed to define the
correct flags mathcing those passed for Fortran sources.
The argument flags was made optional and 2 additional optional arguments
were added i.e. c_flags and cxx_flags.
The default values for featture%flags, feature%c_flags and
feature%cxx_flags were set to an empty string. The latter are set if the
respective optional arguments are defined.

flags, c_flags and cxx_flags are set from the callers
default_release_feature and default_debug_feature.
This way there won't be backward compatibility as the flags were already
defined in the callers.

For now, the c_flags and cxx_flags are limited to the fPIC flag
necessary for the shared libraries except for the variant with the gcc
compiler where equivalent c_flags to flags were defined.
More work is needed to complete the set of c_flags and cxx_flags for
other variants.
@MilanSkocic
Copy link
Author

MilanSkocic commented Nov 15, 2025

I have generalized default_variant and set the c_flags + cxx_flags to values that I think correct. Might need to be revised by somebody that knows compilers very well. My knowledge is limited to gfortran and gcc.
You will find explanations of what I did in the description of the last 4 commits.

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