Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Ruby's have_header method look for header files?

On a CentOS 5.7 box, I'm having trouble installing the newest version of the mysql2 gem; it's not finding errmsg.h:

/usr/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... no
checking for mysql_query() in -lmysqlclient... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
checking for errmsg.h... no
-----
errmsg.h is missing.  please check your installation of mysql and try again.
-----
*** extconf.rb failed ***

The mysql header files exist at /usr/include/mysql. An older version of the gem exists on the server, so it must have been built successfully at one point.

Note that it fails on a check for mysql.h, but succeeds on mysql/mysql.h. However, it doesn't repeat this for errmsg.h. By this I'm guessing that it's not looking at /usr/include, but I'm not sure.

I've dug into the extconf.rb source code and discovered that it's using the have_header method to locate the header files. I debugged the execution to find out that it's looking for a relative path of "mysql/errmsg.h". But I haven't found any documentation that explains how it expands that into an absolute path.

Where & how does have_header locate its header files?

like image 204
Craig Walker Avatar asked Jun 16 '12 23:06

Craig Walker


People also ask

Does Ruby have header files?

You can get these headers in the libruby-dev / libpython-dev Debian packages. These header files live in /usr/include/{ruby-2.3.

Where can I find header files in Linux?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.


1 Answers

I believe I've found an answer.

It appears that have_header looks at the system include path. If the relevant environment variables are not set, the default include paths are /usr/local/include and /usr/include.

If you want to set them manually, you would do something like:

export C_INCLUDE_PATH=/usr/include/mysql/

That's true even if you're compiling a C++ program, if the header file is a C file. If, on the other hand, your header file is C++, not C, you would do:

export CPLUS_INCLUDE_PATH=/usr/include/mysql

Of course, you found the work-around, which is to include dir_config('mysql') in your extconf.rb. That enables you to use the --with-mysql-include option and supply the path manually.

Here's my source: http://www.network-theory.co.uk/docs/gccintro/gccintro_23.html

And here's a more general version of the same question (with answers): How to add a default include path for gcc in linux?

like image 94
Translunar Avatar answered Oct 26 '22 23:10

Translunar