[clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

Tom Eccles via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 1 08:43:57 PST 2023


tblah wrote:

Yes they are mixed source projects. They worked previously because the main function from `Frotran_main` was silently ignored. I don't know if this was accidental or not, but it tended to do the right thing for mixed source projects because if the user intended to use `Fortran_main`, they would not define `main()` elsewhere, but if they did not, there would be another definition of `main()`.

I think the simplest solution would be to add a flag controlling whether to link `Fortran_main`. @DavidTruby suggested only linking `Fortran_main` if the fortran source contains a `program` statement.

One could build a mixed source project now by linking using `clang` and manually specifying to link the rest of the fortran runtime library. I don't think this is a good option because it is not convenient to change spec makefiles and I don't think expecting users to find the right fortran runtime linker invocation is a good experience (a flag just for `Fortran_main` is better because one could see "error: multiple definitions of main()" ... "ahh I need the flag to get rid of the automatic definition of `main()`"). 

https://github.com/llvm/llvm-project/pull/73124


More information about the cfe-commits mailing list