I’m trying to build bpy in headless mode and with static linked libraries. Below is the process I’m using:
# clone blender 4.2.0
make headless bpy release BUILD_CMAKE_ARGS="-DOpenMP_C_FLAGS=-fPIC -DOpenMP_CXX_FLAGS=-fPIC -DWITH_STATIC_LIBS=ON -DWITH_OPENMP_STATIC=ON"
cd ../build_linux_bpy_release_headless; make install
cd ../blender; python3 ./build_files/utils/make_bpy_wheel.py ../build_linux_bpy_release_headless/bin/
The process works, the wheel builds. Then I install the wheel in an environment that does not have libgomp1 installed and attempt to import bpy. It gives me the following error:
ImportError: libgomp.so.1: cannot open shared object file: No such file or directory
I assume that if I was properly statically linking the OpenMP libraries with Blender, then this wouldn’t happen. So what am I doing wrong?
My OS is Debian GNU/Linux 12 (bookworm), if that helps at all.
Note that I tried the above process without the BUILD_CMAKE_ARGS and I had the same issue. I tried to run make deps before make headless bpy release but I’m getting the following error:
libtool: Version mismatch error. This is libtool 2.4.6 Debian-2.4.6-15build2, but the
libtool: definition of this LT_INIT comes from libtool 2.4.7.
libtool: You should recreate aclocal.m4 with macros from libtool 2.4.6 Debian-2.4.6-15build2
libtool: and run autoconf again.
My system does have libgomp.a so I passed OpenMP_LIBRARIES=/usr/lib/gcc/x86_64-linux-gnu/12/libgomp.a. This seems to work now.
I then ran into a series of similar ImportErrors like:
ImportError: libSM.so.6: cannot open shared object file: No such file or directory
As a hacky solution, I copied these Shared Object files on my system into the build_linux_bpy_release_headless/bin/bpy/lib and that seemed to solve the error, even though I know it may cause compatibility issues down the line. This worked until I ran into:
ImportError: libbsd.so.0: cannot open shared object file: No such file or directory
Despite copying libbsd.so.0 into the lib directory, this error still seems to be occurring. Do you know why this could be?
libSM appears to be X11 session management library. libSM depends on libice, which depends on libbsd.
Are you building without the precompiled libraries? In general system libraries are not built for this kind of distribution, so it can get tricky. A library like FFmpeg, OpenImageIO, USD or MaterialX might link to X11 libraries even if Blender does not use that functionatlity in a headless build.
I’m not sure what to suggest besides trying to turn off various build options to figure out which library is the problem.
I am building with the precompiled libraries but I think the X11 dependencies aren’t included in that for some reason. It seems like Blender expects X11 dependencies to be on the system it’s running on.
I followed your advice and tried turning off a variety of libraries. I think the key was WITH_BOOST=OFF. Once I built with that, it seemed to no longer depend on any X11 dependencies and could execute just fine.
Hopefully turning off Boost won’t cause any issues later down the line, I couldn’t find a list of what it enables inside Blender. I’ll report back if I have any issues.