Compilando MySQL com Xcode 4.3 no OS X

Hoje me deparei com um problema ao executar um bundle installem um projeto em que estou trabalhando há um bom tempo. Aparentemente, o MySQL não funciona bem hoje em dia com o Clang, o compilador padrão do Xcode desde 4.3.

Um trecho do meu console:

> bundle install
...
Installing mysql2 (0.3.11)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/guido/.rbenv/versions/1.9.3-p392/bin/ruby extconf.rb
checking
for rb_thread_blocking_region()... yes
checking
for rb_wait_for_single_fd()... yes
checking
for mysql.h... no
checking
for mysql/mysql.h... no
-----
mysql
.h is missing. please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries
and/or headers. Check the mkmf.log file for more
details
. You may need configuration options.
...

No mkmf.logarquivo, temos o seguinte erro:

have_header: checking for mysqld_error.h... -------------------- yes

"gcc -E -I/Users/guido/.rbenv/versions/1.9.3-p392/include/ruby-1.9.1/x86_64-darwin12.3.0 -I/Users/guido/.rbenv/versions/1.9.3-p392/include/ruby-1.9.1/ruby/backward -I/Users/guido/.rbenv/versions/1.9.3-p392/include/ruby-1.9.1 -I. -I'/Users/guido/.rbenv/versions/1.9.3-p392/include' -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I'/Users/guido/.rbenv/versions/1.9.3-p392/include' -I/usr/local/Cellar/mysql/5.6.12/include -Os -g -fno-strict-aliasing -Wno-error=shorten-64-to-32 -pipe conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <mysqld_error.h>
/* end */

Acontece que mysql_configtem algumas opções de compilação que funcionam no GCC, mas não no Clang. As linhas 119 e 120 são os culpados, com as opções -Wno-null-conversione -Wno-unused-private-field:

cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags
="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

Remova os interruptores ruins e tudo funcionará bem:

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags
="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

Nota pequena:

Por padrão, mysql_configestá situado em /usr/local/mysql/bin/mysql_config. Ao usar o homebrew, ele fica em /usr/local/Cellar/mysql/5.6.12/bin/mysql_config, onde 5.6.12está sua versão instalada , é claro.

Fonte:

http://stackoverflow.com/questions/16127493/cc1-error-unrecognized-command-line-option-wno-null-conversion-within-insta