Linking C and Fortran Binaries with gcc
Encountering errors when attempting to link projects containing both C and Fortran code is a common issue when using gcc. This is due to the incompatibility between the required libraries for each language.
To address this issue, you can add the appropriate library flags during the linking stage. When using g for linking, add the '-lgfortran' flag to include the standard Fortran libraries. This ensures that the necessary Fortran library functions are made available for linking with the C code.
Similarly, if you are linking with gfortran, you can add the '-lstdc ' flag to incorporate the standard C library. This ensures that the necessary C library functions are available for linking with Fortran code.
By incorporating these library flags during the linking stage, you can successfully link binaries containing both C and Fortran code, resolving the undefined reference errors that arise when using only one language's compiler.
The above is the detailed content of How to Link C and Fortran Binaries with gcc: A Guide to Avoiding Undefined Reference Errors. For more information, please follow other related articles on the PHP Chinese website!