Search code examples
crubyatlasextconf.rbmkmf

What is the correct usage of have_func when the test function needs arguments?


I have an extconf.rb with the following lines:

have_header("cblas.h")                 # checking for cblas.h... yes
have_func("cblas_dgemm", ["cblas.h"])  # checking for cblas_dgemm() in cblas.h... no
create_header("nmatrix_config.h")      # creating nmatrix_config.h

So, cblas_dgemm is definitely in cblas.h. When I look at mkmf.log, I see that this check actually looks for two things:

  1. a _cblas_dgemm symbol somewhere (?)
  2. a callable cblas_dgemm in cblas.h.

Both tests are failing. I assume the former is failing because I need a dir_config line for cblas, and maybe a have_library('cblas').

But I can't figure out how to make the latter test pass (see line 24 of the gist). Is it possible to pass a block to have_func so it actually calls it with reasonable arguments? Or is there some other way to run this test? Or do I have to have the dir_config stuff setup properly?

Here's line 24, by the way:

conftest.c:7:1: error: too few arguments to function ‘cblas_dgemm’

And yes, of course, cblas_dgemm needs many arguments -- some of them matrices.

It's frustrating how little documentation there is on any of these mkmf functions.


Solution

  • Unfortunately it looks like have_func is pretty poorly documented, but upon some digging I found something that might help:

    [25] pry(main)> have_func("clapack_dgetrf", "/usr/local/atlas/include/clapack.h")
    checking for clapack_dgetrf() in /usr/local/atlas/include/clapack.h... no
    => false
    [26] pry(main)> have_func("int clapack_dgetrf", "/usr/local/atlas/include/clapack.h")
    checking for int clapack_dgetrf() in /usr/local/atlas/include/clapack.h... yes
    => true
    

    So, essentially it looks like you need to include at least the return type to get have_func to work properly. Can you verify that this works on your machine?