title: nvcc + c2hs on OS X 10.9.5
body: <p>I'm building <em>a software</em> that needs <code>nvcc</code> for compilation. I don't have a CUDA-capable GPU, but actually I don't need that – a friend is building the exact same <em>software</em> on Linux, he has no CUDA GPU, but everything's fine.</p>
  
  <p>I installed the newest CUDA toolkit from <a href="https://developer.nvidia.com/cuda-downloads">https://developer.nvidia.com/cuda-downloads</a> (<code>cuda_6.5.14_mac_64.pkg</code>) without an issue. But as I was building <em>the software</em> I got into problems.</p>
  
  <p>I was able to reproduce the issue on the smaller scale:</p>
  
  <pre><code>$ mkdir temp; cd temp; cabal sandbox init
  
  
  $ cabal get cuda
  Unpacking to cuda-0.6.5.0/
  
  
  $ cd cuda-0.6.5.0/Foreign/CUDA/Analysis
  
  
  $ c2hs -d trace --cpp=/Developer/NVIDIA/CUDA-6.5/bin/nvcc --cppopts=-ccbin --cppopts=/usr/bin/clang --cppopts=-Xcompiler --cppopts=--stdlib=libstdc++ Device.chs
  Attempting to read file `Device.chs'...
  ...parsing `Device'...
  ...successfully loaded `Device'.
  Invoking cpp as `/Developer/NVIDIA/CUDA-6.5/bin/nvcc -E -x c -ccbin /usr/bin/clang -Xcompiler --stdlib=libstdc++ -U__BLOCKS__ -DC2HS_MIN_VERSION(mj,mn,rv)=(mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2) Device.chs.h'...
  In file included from &lt;built-in&gt;:170:
  &lt;command line&gt;:3:29: error: expected comma in macro parameter list
  #define C2HS_MIN_VERSION(mj 1
                              ^
  &lt;command line&gt;:5:11: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions]
  #define rv) (mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2)
            ^
  Device.chs.h:1:10: fatal error: 'cbits/stubs.h' file not found
  #include "cbits/stubs.h"
           ^
  1 warning and 2 errors generated.
  c2hs: Error during preprocessing custom header file
  </code></pre>
  
  <p>With the trace in hand, I was able to go deeper into the rabbit hole:</p>
  
  <pre><code>$ /Developer/NVIDIA/CUDA-6.5/bin/nvcc -E -x c -ccbin /usr/bin/clang -Xcompiler --stdlib=libstdc++ -U__BLOCKS__ -DC2HS_MIN_VERSION(mj,mn,rv)=(mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2) Device.chs.h
  zsh: parse error near `)'
  
  
  $ /Developer/NVIDIA/CUDA-6.5/bin/nvcc -E -x c -ccbin /usr/bin/clang -Xcompiler --stdlib=libstdc++ -U__BLOCKS__ -D'C2HS_MIN_VERSION(mj,mn,rv)=(mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2)' Device.chs.h
  # 1 "Device.chs.h"
  # 1 "&lt;built-in&gt;" 1
  # 1 "&lt;built-in&gt;" 3
  # 170 "&lt;built-in&gt;" 3
  # 1 "&lt;command line&gt;" 1
  In file included from &lt;built-in&gt;:170:
  &lt;command line&gt;:3:29: error: expected comma in macro parameter list
  #define C2HS_MIN_VERSION(mj 1
                              ^
  &lt;command line&gt;:5:11: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions]
  #define rv) (mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2)
            ^
  # 1 "&lt;built-in&gt;" 2
  # 1 "Device.chs.h" 2
  Device.chs.h:1:10: fatal error: 'cbits/stubs.h' file not found
  #include "cbits/stubs.h"
           ^
  
  1 warning and 2 errors generated.
  
  
  $ Developer/NVIDIA/CUDA-6.5/bin/nvcc -x c -D 'C2HS_MIN_VERSION(mj,mn,rv)=(mj&lt;=0&amp;&amp;mn&lt;=18&amp;&amp;rv&lt;=2)' Device.chs.h
  (same issue)
  </code></pre>
  
  <p>I have no idea how to fix that. By the way, both <code>clang</code> and <code>gcc</code> are okay with passing macros with arguments via <code>-D</code>.</p>
  
  <p>Probably relevant:</p>
  
  <pre><code>$ echo $PATH
  /Users/konrad/bin:/Users/konrad/.ghc-current/bin:/Users/konrad/.cabal/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Developer/NVIDIA/CUDA-6.5/bin
  
  $ echo $DYLD_LIBRARY_PATH
  /Developer/NVIDIA/CUDA-6.5/lib:
  
  $ echo $LD_LIBRARY_PATH
  /usr/local/cuda/lib:
  
  $ ghc --version
  The Glorious Glasgow Haskell Compilation System, version 7.8.3
  
  $ cabal --version
  cabal-install version 1.20.0.3
  using version 1.20.0.0 of the Cabal library
  
  $ c2hs --version
  C-&gt;Haskell Compiler, version 0.18.2 The shapeless maps, 31 Oct 2014
    build platform is "x86_64-darwin" &lt;1, True, True, 1&gt;
  
  $ gcc --version
  Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
  Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
  Target: x86_64-apple-darwin13.4.0
  Thread model: posix
  
  $ gcc-4.9 --version
  gcc-4.9 (GCC) 4.9.0 20140411 (prerelease)
  Copyright (C) 2014 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>I have Intel Iris Pro 5100 (mbp retina 15" late 2013).</p>