title: How to compile (make) in a directory with a hashtag in its name?
body: <p>(TL;DR at the bottom)</p>
  
  <p>I have a c++ project which I am able to compile successfully using</p>
  
  <pre><code>mkdir build &amp;&amp; cd build
  cmake ..
  make
  </code></pre>
  
  <p>However, because I didn't want my cloud-synchronization program to sync this, I named this folder not <code>build</code>, but <code>_#build</code> instead. this caused make to output this:</p>
  
  <pre><code>/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
  /bin/sh: -c: line 1: syntax error: unexpected end of file make: ***
  [Makefile:190: cmake_check_build_system] Error 1
  </code></pre>
  
  <p>After experimenting around with different names for the build folder - `~build~ seems to work for example - I noticed that cmake's output differs by one line when the dirname contains a hashtag (#) sign.</p>
  
  <blockquote>
    <p>-- Detecting CXX compile features - failed</p>
  </blockquote>
  
  <p>Without the hashtag, it says "done" instead of "failed".</p>
  
  <p>For this specific case, I just told my sync tool to also ignore directories that are named "build" and just used the dirname "build", but I am still wondering how I could workaround this if I wanted to keep the hashtag in the name. This is my question: How could I run make successfully within a directory that contains <code>#</code> in its name?</p>
  
  <p>Please note that this happened on cygwin and I am not sure whether this would also happen on a native bash shell.</p>
  
  <p><strong>First Edit</strong></p>
  
  <p>As suggested by Patrick Kelly, I tried to replace all occurences in the paths within the Makefile from <code>_#build</code> to <code>_\#build</code>. I did so manually, and after making sure there were no other occurences also using <code>sed</code>.
  This did not work when I then tried to run <code>make</code>, so I tried to just replace every occurence of <code>_#build</code> in any file in any subfolder - I figure there won't be any occurences outside of paths. Just to make sure there's nothing left unchanged. So what I did was:</p>
  
  <p><code>$ grep --null -l '_#build' -r . | xargs -0 sed -i 's/_#build/_\\#build/g'</code></p>
  
  <p>I don't really understand why I had to escape the backslash, I thought single quotes didn't evaluate it. But anyways, this also didn't work. Short explanation of this command: grep lists all filenames (<code>-l</code>) of the found occurrences in any subfolder (<code>-r</code>) and separates them with nullcharacteres (<code>--null</code>) such that xargs applies sed to all of these files. the sed command itself does the replacement for all occurences in a file.</p>
  
  <p>The problem now:</p>
  
  <pre><code>make
  
  Call Stack (most recent call first):
    /usr/share/cmake-3.6.2/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
    CMakeLists.txt:5 (PROJECT)
  
  -- Configuring incomplete, errors occurred!
  See also "/cygdrive/c/Users/myUser/Documents/temp/_#build/CMakeFiles/CMakeOutput.log".
  See also "/cygdrive/c/Users/myUser/Documents/temp/_#build/CMakeFiles/CMakeError.log".
  make: *** [Makefile:190: cmake_check_build_system] Error 1
  </code></pre>
  
  <p>And CMakeError.log contains for "Run Build Command" and for "Detecting CXX [-std=c++14] compiler features ..." the following (not pasting the whole thing).
  Detecting CXX [-std=c++14] compiler features failed to compile with the following output:</p>
  
  <pre><code>Change Dir: /cygdrive/c/Users/myUser/Documents/temp/_\#build/CMakeFiles/CMakeTmp
  
  Run Build Command:"/usr/bin/make.exe" "cmTC_1dcec/fast"
  /usr/bin/make -f CMakeFiles/cmTC_1dcec.dir/build.make CMakeFiles/cmTC_1dcec.dir/build
  make[1]: Entering directory '/cygdrive/c/Users/myUser/Documents/temp/_\#build/CMakeFiles/CMakeTmp'
  make[1]: *** No rule to make target '/cygdrive/c/Users/myUser/Documents/temp/_', needed by 'CMakeFiles/cmTC_1dcec.dir/feature_tests.cxx.o'.  Stop.
  </code></pre>
  
  <p>So apparently, I inserted the backslash at too many places, huh?
  The simple solution: I didn't need to change all occurences in my Makefile. What I had to replace:</p>
  
  <pre><code>CMAKE_BINARY_DIR = "/cygdrive/c/Users/myUser/Documents/temp/_\#build"
  </code></pre>
  
  <p>What I had to leave as it was:</p>
  
  <pre><code>all: cmake_check_build_system
      $(CMAKE_COMMAND) -E cmake_progress_start "/cygdrive/c/Users/myUser/Documents/temp/t/_#build/CMakeFiles" "/cygdrive/c/Users/myUser/Documents/temp/t/_#build/CMakeFiles/progress.marks"
      $(MAKE) -f CMakeFiles/Makefile2 all
      $(CMAKE_COMMAND) -E cmake_progress_start "/cygdrive/c/Users/Eric/Documents/temp/t/_#build/CMakeFiles" 0
  </code></pre>
  
  <p>Also, no need to change any other files than the Makefile.</p>
  
  <blockquote>
    <p><strong>TL;DR</strong></p>
    
    <p>Only change the line with <code>CMAKE_BINARY_DIR</code> to <code>CMAKE_BINARY_DIR =
    "/cygdrive/c/Users/myUser/Documents/temp/_\#build"</code></p>
  </blockquote>
  
  <p>Because the path I needed to replace was the first occurrence in the Makefile, the following bash command did the trick for me to automatize it.</p>
  
  <pre><code>sed -i 's/_#build/_\\#build/' Makefile
  </code></pre>