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

351 Views Asked by At

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.

2

There are 2 best solutions below

1
acsmith On BEST ANSWER

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?

0
user1614572 On

In mkmf.rb of ruby 1.9.3p392, The latter test is executed only if the former fails. When the former passes, have_func successes. So you don't have to make the latter pass. Refer to try_func in mkmf.rb for more details.

Just for information, in mkmf.rb on 2013-04-13 11:00:25, it seems you can give arguments like this: have_func("some_func(some_arg, another_arg)", ["foo.h"]).