[PATCH] D126291: [flang][Driver] Update link job on windows

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 3 10:05:16 PDT 2022


mstorsjo added a comment.

In D126291#3556096 <https://reviews.llvm.org/D126291#3556096>, @mmuetzel wrote:

> The error message I get without `-lc++`:
>
>   ld.lld: error: undefined symbol: std::__1::mutex::lock()
>   >>> referenced by libFortranRuntime.a(io-api.cpp.obj):(Fortran::runtime::io::IoStatementState* Fortran::runtime::io::BeginExternalListIO<(Fortran::runtime::io::Direction)0, Fortran::runtime::io::ExternalListIoStatementState>(int, char const*, int))
>   >>> referenced by libFortranRuntime.a(io-api.cpp.obj):(Fortran::runtime::io::IoStatementState* Fortran::runtime::io::BeginExternalListIO<(Fortran::runtime::io::Direction)0, Fortran::runtime::io::ExternalListIoStatementState>(int, char const*, int))
>   >>> referenced by libFortranRuntime.a(io-api.cpp.obj):(Fortran::runtime::io::IoStatementState* Fortran::runtime::io::BeginExternalListIO<(Fortran::runtime::io::Direction)1, Fortran::runtime::io::ExternalListIoStatementState>(int, char const*, int))
>   >>> referenced 36 more times
>   
>   ld.lld: error: undefined symbol: std::__1::mutex::unlock()
>   >>> referenced by libFortranRuntime.a(unit.cpp.obj):(Fortran::runtime::io::FlushOutputOnCrash(Fortran::runtime::Terminator const&))
>   >>> referenced by libFortranRuntime.a(unit.cpp.obj):(Fortran::runtime::io::ExternalFileUnit::LookUp(int))
>   >>> referenced by libFortranRuntime.a(unit.cpp.obj):(Fortran::runtime::io::ExternalFileUnit::GetUnitMap())
>   >>> referenced 23 more times
>   flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
>
> Edit: That's probably because of this:
> https://github.com/llvm/llvm-project/blob/main/flang/runtime/lock.h
>
>   // Avoid <mutex> if possible to avoid introduction of C++ runtime
>   // library dependence.
>   #ifndef _WIN32
>   #define USE_PTHREADS 1
>   #else
>   #undef USE_PTHREADS
>   #endif
>   
>   #if USE_PTHREADS
>   #include <pthread.h>
>   #else
>   #include <mutex>
>   #endif
>
> So, there will be a C++ runtime library dependency on Windows.

If the only need is for mutexes, using a corresponding native windows api is quite straightforward. (If other synchronization primitives are needed, it may require a bit more effort.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126291/new/

https://reviews.llvm.org/D126291



More information about the cfe-commits mailing list