[flang-commits] [clang] [flang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)
Michael Klemm via flang-commits
flang-commits at lists.llvm.org
Thu Dec 7 08:55:16 PST 2023
mjklemm wrote:
Thanks for the reproducer.
> The error shows up when linking a C program with a Fortran shared library, so maybe you weren't enabling building shared libraries?
I was building OpenBLAS using the "old" Makefile-based build. There the issue indeed does not happen. When I switched to your CMake configuration line, I was able to reproduce the problem.
The solution is to add `-fno-fortran-main` to the linker options via `CMAKE_SHARED_LINKER_FLAGS`. This will need PR https://github.com/llvm/llvm-project/pull/74139 land first. But this option will be a good way to control if the flang compiler should attempt linking in the `main` stub from its library.
It seems like `flang-new` when being used as a linker with `-shared` included Fortran_main in the shared library. This seems wrong to me. The option `-fno-fortran-main` avoids this. I'm pondering if `-shared` is buggy here. It will require a bit more digging on my end to figure that out.
https://github.com/llvm/llvm-project/pull/73124
More information about the flang-commits
mailing list