Home > Backend Development > C++ > How to Link C and Fortran Binaries with gcc: A Guide to Avoiding Undefined Reference Errors

How to Link C and Fortran Binaries with gcc: A Guide to Avoiding Undefined Reference Errors

Mary-Kate Olsen
Release: 2024-10-26 04:21:30
Original
681 people have browsed it

How to Link C   and Fortran Binaries with gcc: A Guide to Avoiding Undefined Reference Errors

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template