<div data-ntes="ntes_mail_body_root" style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div style="margin:0;">I write a gfortran program omp.f90 as following</div><div style="margin:0;"><br></div><div style="margin:0;">use omp_lib</div><div style="margin:0;">!$omp parallel</div><div style="margin:0;">  write(*,*) "threads", omp_get_num_threads()</div><div style="margin:0;">  !$omp end parallel</div><div style="margin:0;">end</div><div style="margin:0;"><br></div><div style="margin:0;">compile omp.f90 with "gfortran -fopenmp -o omp omp.f90 -static"</div><div style="margin:0;">./omp abort</div><div style="margin:0;">The reson is static executable invoke destroy_unit_mutex which is defined in libgfortran.a. </div><div style="margin:0;">destroy_unit_mutex invoke pthread_mutex_destroy, but this is a weakref. So linker does not find the definition of pthread_mutex_destroy in libpthread.a. Finally, static executable omp does not contain</div><div style="margin:0;">the definition of pthread_mutex_destroy, so omp error when it invoke pthread_mutex_destroy.</div><div style="margin:0;"><br></div><div style="margin:0;">The code about "weakref will not find it definition in static library" as following.</div><div style="margin:0;"><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">     </span>      if (h->type != bfd_link_hash_undefweak)</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">           </span>/* Symbol must be defined.  Don't check it again.  */</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">           </span>included[i] = true;</span></div><div style="margin:0;"><br></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">  </span>      if (!is_elf_hash_table (info->hash))</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">              </span>continue;</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre"> </span>      struct elf_link_hash_entry *eh</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">               </span>= (struct elf_link_hash_entry *) h;</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">       </span>      /* Ignore the archive if the symbol isn't referenced by a</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">            </span> regular object or isn't defined in a shared object.  */</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">     </span>      if (!eh->ref_regular || !eh->def_dynamic)</span></div><div style="margin:0;"><span style="white-space: normal;"><span style="white-space:pre">              </span>continue;</span></div><div><br></div><div><div>Why can't weakref look for definitions in the static library, is there a way to statically compile omp.f90? I defined SUPPORTS_WEAK as 0 in the libgfortran directory of the gcc repository, and the generated libgfortran.a enables omp.f90 to be compiled statically, but the generated libgfortran.so gets an error when adding it to the link process because of the pthread_mutex_destroy and other functions are no longer weakref, the linking process does not find the definitions of these functions.</div><div><br></div></div></div></div><img style="width:1px;height:1px" src="https://count.mail.163.com/beacon/webmail.gif?type=webmail_mailtrace&guid=pre_fd0678d2f07ee1edfb43ef4207d46d7f">