openmopac / mopac

Molecular Orbital PACkage
http://openmopac.net
GNU Lesser General Public License v3.0
115 stars 31 forks source link

Static build broken #142

Closed mbanck closed 11 months ago

mbanck commented 1 year ago

Describe the bug

Is the static build (-DSTATIC_BUILD=ON) tested regularly? I just tried it and then the tests fails with segfaults:

1: 
1: Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
1: 
1: Backtrace for this error:
  1/118 Test   #9: compare_proteins .................***Failed    0.47 sec
Backtrace for this error:
#0  0x6d65b2 in ???
#1  0x6d5c15 in ???
#2  0x74e45f in ???
#3  0x0 in ???
In attempting to run:  ['/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/mopac', 'Compare_two_protein_structures.mop']
stdout:  None
stderr:  None
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/tests/run_test.py", line 29, in <module>
    out_line, out_list = parse_mopac_out_file(out_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<<PKGBUILDDIR>>/tests/compare_output.py", line 61, in parse_mopac_out_file
    with open(path,'r') as file:
         ^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'Compare_two_protein_structures.out'
[...]
0% tests passed, 118 tests failed out of 118

To Reproduce

Configure CMake with DSTATIC_BUILD=ON and run CTest

Expected behavior

Tests pass.

Operating system

Debian unstable

susilehtola commented 1 year ago

Verified on Fedora.

godotalgorithm commented 1 year ago

The static build option was a contributed feature from mid-2022 (#35), and I have not been actively testing it as other aspects of the build system were modified. Code coverage of MOPAC is only at 67% at the moment, and while expanding coverage is a high priority in 2023, active coverage of this particular feature is a low priority relative to other, core features of MOPAC.

On my Mac, I'm getting BLAS/LAPACK linking errors that are preventing the static executable from being built at the moment. I'll look into fixing this. It's probably a quick fix, but sometimes this kind of problem can be stubborn to diagnose.

godotalgorithm commented 1 year ago

I've been looking into this some more. Fully static linking isn't possible on Mac because many system libraries are only available as shared libraries. Static linking seems to be possible on Linux, but you need to make sure all necessary static libraries are available (including low-level system libraries like libm & libc) and they are often not availably by default. I'm doing Linux development on an HPC system right now, and static versions of many libraries (including libm & libc) are not available to perform or test a static build.

Do CMake and Make also flag errors or warnings when you try to perform a static build?

I don't think static builds are a feature that can be expected to work "out of the box" for most people. I'm not sure there is anything for me to do here except perhaps to add a warning message about the requirements of a successful static build.

godotalgorithm commented 11 months ago

After a closer examination of this issue, I've determined that the most likely culprit in a failed static build is the OpenMP linking. I've added an extra warning message to the static build option that directs users to set THREADS_KEYWORD=OFF if their static build fails. I've also added a test of the static build to the routine CI process, and I can statically build MOPAC without any problems as long as OpenMP is off.

From a quick Google search, it seems like static linking of OpenMP is possible, but it ends up being very platform-specific. I'm fine with MOPAC having static build options, but getting a static build working with OpenMP is an extremely low priority for me.