Skip to content

Instantly share code, notes, and snippets.

@xinyazhang
Created May 6, 2021 22:05
Show Gist options
  • Select an option

  • Save xinyazhang/f3af94b7134d7f736cdee07b0570369b to your computer and use it in GitHub Desktop.

Select an option

Save xinyazhang/f3af94b7134d7f736cdee07b0570369b to your computer and use it in GitHub Desktop.
Compile GCC-8 From Source for Matlab 2020B
# Install to /opt/gcc-8
# Do NOT install to /usr/local, because of libstdc++.so.6 naming conflict.
# Your system's compiler are likely incompatible with it.
# There is also no "library-suffix" option. So simply don't install it there.
# Optionally you can add --program-suffix=-8 but this creates quite a few troubles for Matlab to detect GCC.
../gcc-8.4.0/configure --prefix=/opt/gcc-8 --enable-bootstrap --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --build=x86_64-redhat-linux --disable-multilib
# Important. Run this in your shell before "make", otherwise there will be various weird erros.
# Don't know why gcc don't make this default.
unset LIBRARY_PATH CPATH C_INCLUDE_PATH PKG_CONFIG_PATH CPLUS_INCLUDE_PATH INCLUDE
@xinyazhang
Copy link
Author

And add the following to startup.m

% Do NOT use addpath, it won't touch $PATH for !which gcc
setenv('PATH', ['/opt/gcc-8/bin:' getenv('PATH')]);
% Don't know if your distro uses lib or lib64 or whatever, just add all of
% them. If it still doesn't work please run "find /opt/gcc-8|grep libstdc++.so"
% to figure out the right path.
setenv('LD_LIBRARY_PATH', ['/opt/gcc-8/lib64:/opt/gcc-8/lib:' getenv('LD_LIBRARY_PATH')]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment