CO2 Fortran Binary not found and How To Handle Old Binaries #21
Knguyen-dev
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
Our Python web app is running Alpine Linux (via a Docker container), which is needed for our UV package manager. This app needs to execute a Fortran binary called
main, which performs CO2 solubility calculations. Even thoughmainis present in the file system, and marked as executable (we gave file perms inDockerfile), we had issues running it. First we saw that when our web app tried to run the file, we got a "Permission denied" error. Then, after doing docker exec inside the container, we saw that themainbinary didn't have execution permissions. That's straightforward, we just need to give the container execution permissions.But now, when trying to run the binary, we're getting "File not found", which is different and a little misleading. We went into our container and ran some commands
Even though the file exists and has execution permissions, it's doesn't show up? It's not running? This can happen when a binary depends on other files (shared libraries), and those dependencies aren't available in the container. So those "file not found" messages were a bit misleading. Here's how we found the dependencies weren't there:
We're running our app in an Alpine Linux container, which is minimal and uses a library called musl instead of the usual glibc used by most Linux distros. To give background, these are different implementation's of the C standard library. So C has a set of specifications for the functions to be provided in its "standard" library. glibc is a popular implementation of that standard library. Musl is mainly used in light-weight settings, but in general most binaries you'll see are compiled on systems that use glibc. Our Fortran library was compiled in glibc so it expects glibc and specific glibc functions to exist. However, since Alpine doesn't have that, it's not going to work. To solve this, we'll install
gcompat, which is a compatibility layer for glib on musl systems.Now exec into the container and try running the program:
Let me explain what each of those do again:
gfortran: This is a GNU Fortran compiler, so you'll need this if you're compiling Fortran code inside the Docker container. However, if you are just running a precompiled binary, you don't need this. So this is not needed since we're only running pre-compiled binaries, but I'll still mention it in case someone in the future wants to add the fortran source code here and compile them here.libgfortran: A runtime library used by Fortran programs compiled withgfortran. It's required if your binary was compiled withgfortranand uses its features, which most do. And finally we also know it's necessary since it was present in the ldd error logs.libgcc: GCC runtime support, needed for exception handling and other routines. Honestly you don't really need to know this in-depth, all you know is it's a dependency that was listed on thelddcommand for things that were missing so we add i.gcompat: Alpine usesmusl libcinstead ofglibc; most binaries (like ours) expectglibc. This software is a compatibility layer that lets glibc compiled binaries run onmusland therefore Alpine.So in summary, Alpine uses musl to compile binaries, but many programs (like our Fortran binary) are compiled with glibc. We can install
gcompatto let these glibc-compiled binaries run properly on Alpine by mimicking the behavior and structure that glibc-based programs expect. So, for future developers, here's some advice:If you're using Alpine Linux and a precompiled binary gives a weird "file not found" error, even though the file is there:
Beta Was this translation helpful? Give feedback.
All reactions