Feature #4924

mkmf have_header fails with C++ headers

Added by adgar (Michael Edgar) over 8 years ago. Updated about 2 years ago.

Target version:


When a user calls (({have_header('some_cpp_header.h')})), and then header includes a line such as(({ #include })), mkmf will fail.

An example run follows:

  • extconf.rb

require 'mkmf'

  • mkmf.log have_header: checking for BasicBlock.h... -------------------- no

"gcc -E -I/Users/michaeledgar/.rvm/rubies/ruby-1.9.2-head/include/ruby-1.9.1/x86_64-darwin10.7.0 -I/Users/michaeledgar/.rvm/rubies/ruby-1.9.2-head/include/ruby-1.9.1/ruby/backward -I/Users/michaeledgar/.rvm/rubies/ruby-1.9.2-head/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe conftest.c -o conftest.i"
In file included from conftest.c:3:
./BasicBlock.h:4:18: error: vector: No such file or directory
./BasicBlock.h:5:21: error: exception: No such file or directory
./BasicBlock.h:6:21: error: stdexcept: No such file or directory
checked program was:
/* begin /
1: #include "ruby.h"
3: #include
end */

The issue here is that the temporary file created to perform the header test is ((%conftest.c%)), not (( or ((%conftest.cpp%)). Changing the
name of the file and re-running gcc gives success.

In ((%mkmf.rb%)), have_header executes cpp_command, which creates the shell command to run. However, cpp_command uses the constant (({CONFTEST_C = "conftest.c"})). It should use a new constant, (({CONFTEST_CPP = ""})).

I've attached a patch that does this as expected. Tests pass; I'm unsure precisely how to construct
a test case that would be appropriate for the Ruby trunk. There are very few guiding examples in the
existing test suite.

Related issues

Related to Ruby master - Feature #3330: mkmf (find|have)_cxx_headerRejectedActions
Is duplicate of Ruby master - Feature #3333: mkmf (have|find)_cxx_headerRejectedActions



Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Tracker changed from Bug to Feature
  • Priority changed from Normal to 3

Updated by mame (Yusuke Endoh) almost 8 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by mame (Yusuke Endoh) about 7 years ago

  • Target version set to 2.6

Updated by mame (Yusuke Endoh) about 2 years ago


Updated by mame (Yusuke Endoh) about 2 years ago

  • Related to deleted (Feature #3333: mkmf (have|find)_cxx_header)

Updated by mame (Yusuke Endoh) about 2 years ago

  • Is duplicate of Feature #3333: mkmf (have|find)_cxx_header added

Updated by naruse (Yui NARUSE) about 2 years ago

  • Target version deleted (2.6)

Also available in: Atom PDF