Building Blender from source with static linking I'm following these instructions to build Blender from source as a Python module. As I need to share my build with others in a different runtime environment, I need to build it with static linking.

I did

cmake ../blender -DPYTHON_LIBRARY="/home/anaconda3/envs/project/lib/libpython3.6m.a" -DPYTHON_INCLUDE_DIR="/home/anaconda3/envs/project/include/python3.6m" -DOPENIMAGEIO_LIBRARY="$HOME/blender-deps/built/oiio/lib/libOpenImageIO.so" -DOPENIMAGEIO_INCLUDE_DIR="$HOME/blender-deps/built/oiio/include" -DWITH_PYTHON_MODULE=ON -DWITH_PYTHON_INSTALL=OFF -DWITH_STATIC_LIBS=ON
make -j; make install


and failed at the very end

[100%] Building C object source/creator/CMakeFiles/blender.dir/creator_args.c.o
[100%] Building C object source/creator/CMakeFiles/blender.dir/buildinfo.c.o
[100%] Linking CXX shared module ../../bin/bpy.so
lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005
Please submit a full bug report,
with preprocessed source if appropriate.
See &lt;file:///usr/share/doc/gcc-7/README.Bugs&gt; for instructions.
lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
compilation terminated.
/usr/bin/ld.gold: fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status
source/creator/CMakeFiles/blender.dir/build.make:319: recipe for target 'bin/bpy.so' failed
make[2]: *** [bin/bpy.so] Error 1
CMakeFiles/Makefile2:7690: recipe for target 'source/creator/CMakeFiles/blender.dir/all' failed
make[1]: *** [source/creator/CMakeFiles/blender.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2


This error is too obscure for me to figure out what is wrong.
The most relevant line here is: 

lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005 Please submit a full bug report

The compiler has hit code that caused it to fail.  It's not possible to continue this build without fixing the compiler, or changing compilers.

I encourage you to submit a bug report.  gcc-7 is still widely deployed and this will definitely get looked at.