This article was machine-translated from the Japanese version.
What happened
In Mastodon v2.8.1, a bug occurred where gem install blurhash would fail in certain environments. This issue has been fixed in v2.8.2.
https://mstdn.jp/@yi0713/102008223252331858
CentOS勢、masterに追加された blurhash というgemのインストールでコケると思います。原因は gcc が 4.8.5 と古いためのようです
https://mastodon.social/@Mastodon/102044104623035256
Some people have reported problems installing Mastodon v2.8.1 due to gem compilation.
This and a few other small bugs have been fixed in #Mastodon v2.8.2
Reproducing the bug
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
$ gem install blurhash -v 0.1.2
Building native extensions. This could take a while...
ERROR: Error installing blurhash:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
creating Makefile
make "DESTDIR="
gcc -I. -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -m64 -o encode.o -c encode.c
encode.c: In function 'blurHashForPixels':
encode.c:28:2: error: 'for' loop initial declarations are only allowed in C99 mode
for(int y = 0; y < yComponents; y++) {
^
encode.c:28:2: note: use option -std=c99 or -std=gnu99 to compile your code
encode.c:29:3: error: 'for' loop initial declarations are only allowed in C99 mode
for(int x = 0; x < xComponents; x++) {
^
encode.c:48:3: error: 'for' loop initial declarations are only allowed in C99 mode
for(int i = 0; i < acCount * 3; i++) {
^
encode.c:62:2: error: 'for' loop initial declarations are only allowed in C99 mode
for(int i = 0; i < acCount; i++) {
^
encode.c: In function 'multiplyBasisFunction':
encode.c:75:2: error: 'for' loop initial declarations are only allowed in C99 mode
for(int y = 0; y < height; y++) {
^
encode.c:76:3: error: 'for' loop initial declarations are only allowed in C99 mode
for(int x = 0; x < width; x++) {
^
encode.c: In function 'encode_int':
encode.c:129:2: error: 'for' loop initial declarations are only allowed in C99 mode
for(int i = 0; i < length - 1; i++) divisor *= 83;
^
encode.c:131:10: error: redefinition of 'i'
for(int i = 0; i < length; i++) {
^
encode.c:129:10: note: previous definition of 'i' was here
for(int i = 0; i < length - 1; i++) divisor *= 83;
^
encode.c:131:2: error: 'for' loop initial declarations are only allowed in C99 mode
for(int i = 0; i < length; i++) {
^
make: *** [encode.o] Error 1
Gem files will remain installed in /usr/local/share/gems/gems/blurhash-0.1.2 for inspection.
Results logged to /usr/local/share/gems/gems/blurhash-0.1.2/ext/blurhash/gem_make.out
Cause
As shown in the error during reproduction, this is because int i is declared within the for loop. This specification was introduced in C99, and requires -std=c99 to be specified during compilation.
In Mastodon v2.8.2, an update was made to upgrade blurhash from v0.1.2 to v0.1.31, and in blurhash v0.1.3, a fix was implemented to specify $CFLAGS += ' -std=c99 -lm' during compilation2.
Background of the Issue
This issue occurred on CentOS 7 but not on Ubuntu 16.04. This is due to the difference in the gcc versions installed via the package management systems.
CentOS 7 installs 4.8.5 20150623 (Red Hat 4.8.5-36), while Ubuntu installs 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10).
From gcc version 5 onwards, the default std option was changed to gnu11. This is an extension of c11, and since c11 is newer than c99, it includes the aforementioned specification. Therefore, it is no longer necessary to specify -std=c99.
https://www.gnu.org/software/gcc/gcc-5/changes.html
The default mode for C is now -std=gnu11 instead of -std=gnu89.
Aside
cflags can be specified when running gem install.
$ gem install blurhash -v 0.1.2 -- --with-cflags="-std=c99"
Building native extensions with: '--with-cflags=-std=c99'
This could take a while...
Successfully installed blurhash-0.1.2
Parsing documentation for blurhash-0.1.2
Installing ri documentation for blurhash-0.1.2
1 gem installed