# Mkmf.rb $B$N(B C++ $BBP1~(B

**URL:** <https://www.ruby-forum.com/t/mkmf-rb-b-n-b-c-bbp1-b/160755>\
**Category:** Development\
**Created:** [February 19, 2009, 10:56am UTC](https://www.ruby-forum.com/t/mkmf-rb-b-n-b-c-bbp1-b/160755 "2009-02-19T10:56:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KISHIMOTOS\_Makoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8baadc/32.png) [@KISHIMOTOS\_Makoto](https://www.ruby-forum.com/u/KISHIMOTOS_Makoto)\
**Post date:** [February 19, 2009, 10:56am UTC](https://www.ruby-forum.com/t/mkmf-rb-b-n-b-c-bbp1-b/160755/1 "2009-02-19T10:56:21Z")

</div>

e$B$-$7$b$H$G$9e(B

C++ e$B$N%X%C%@$@$H!“8=:\_$Ne(B (have|find)\_header  
e$B$G$O$&$^$/H=Dj$G$-$J$$e(B  
e$B$3$H$,$”$k$N$G!Je(B cc -E e$B$@$H$?$H$($Pe(B #include  
e$B$H$+$G$&$^$/$J$$!Ke(B  
(have|find)_cxx\_header e$B$H$$$&%3%^%s%I$rDI2C$7$F$_$^$7$?!#e(B

C++ e$B$N%W%j%W%m%;%C%5$N$?$a$Ne(B config  
e$B$,$&$^$/$o$+$i$J$+$C$?$N$G!"e(B  
C++ e$B%3%s%Q%$%i$K$+$1$F%A%’%C%/$7$F$$$^$9!#e(BBoost  
e$B$N5pBg$J%X%C%@$H$+$Ge(B  
e$B%A%’%C%/$@$1$J$N$KL5Cc6lCc;~4V$r$+$1$F$7$^$&$H$$$&LdBj$,=P$k$+$be(B  
e$B$7$l$^$;$s!#e(B

# Index: lib/mkmf.rb

— lib/mkmf.rb (revision 22439)  
+++ lib/mkmf.rb (working copy)  
@@ -400,6 +400,14 @@  
conf)  
end

+def cxx\_command(opt="")

- conf = RbConfig::CONFIG.merge(‘hdrdir’ =\> $hdrdir.quote, ‘srcdir’ =\>  
$srcdir.quote,
- 

```
                           'arch_hdrdir' => "#$arch_hdrdir",

```

- 

```
                           'top_srcdir' => $top_srcdir.quote)

```

- RbConfig::expand("$(CXX) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH\_FLAG  
#{opt} -c #{CONFTEST\_C}",
- 

```
  conf)

```

+end  
+  
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)  
libpath.map{|x|  
case x  
@@ -437,6 +445,12 @@  
alias\_method :try\_header, (config\_string(‘try\_header’) || :try\_cpp)  
end

+def try\_cxx(src, opt="", &b)

- try\_do(src, cxx\_command(opt), &b)  
+ensure
- rm\_f “conftest\*”  
+end
- 

def cpp\_include(header)  
if header  
header = [header] unless header.kind\_of? Array  
@@ -819,6 +833,17 @@  
end  
end

+def have\_cxx\_header(header, preheaders = nil, &b)

- checking\_for header do
- if try\_cxx(cpp\_include(preheaders)+cpp\_include(header), &b)
- 

```
 $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))

```

- 

```
 true

```

- else
- 

```
 false

```

- end
- end  
+end
- 

# Instructs mkmf to search for the given +header+ in any of the +paths+

# provided, and returns whether or not it was found in those paths.

# 

@@ -846,6 +871,27 @@  
end  
end

+def find\_cxx\_header(header, \*paths)

- message = checking\_message(header, paths)
- header = cpp\_include(header)
- checking\_for message do
- if try\_cxx(header)
- 

```
 true

```

- else
- 

```
 found = false

```

- 

```
 paths.each do |dir|

```

- 

```
   opt = "-I#{dir}".quote

```

- 

```
   if try_cxx(header, opt)

```

- 

```
     $INCFLAGS << " " << opt

```

- 

```
     found = true

```

- 

```
     break

```

- 

```
   end

```

- 

```
 end

```

- 

```
 found

```

- end
- end  
+end
- 

# Returns whether or not the struct of type +type+ contains +member+.

If

# it does not, or the struct type can’t be found, then false is

returned. You

# may optionally specify additional +headers+ in which to look for the

struct
