title: GCC doesn't compile when called by system() in Ruby
body: <p>GCC compiles my C script when it's called on the command line by using 
  <code>gcc main.c -o bfcout</code>. I wrote a script in Ruby where line 36 says <code>system("gcc main.c -o bfcout")</code>. I also tried <code>bash -c #{Shellwords.escape("gcc -Wall #{filename}.c -o bfcompoutput")}</code>.</p>
  
  <p>But I get an error: <code>/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib/crt1.o: In function '_start':
  (.text+0x20): undefined reference to 'main'</code></p>
  
  <p>There IS a main() function, and as I said, compiling on the command line works! What is wrong here?</p>
  
  <p>EDIT: 
  C file looks like this. It is generated by the script. And yes, it's a reference to Brainf***. Sorry for the many lines(and the bad formatting).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  unsigned char _c[30000]={};
  int ptr=0;
  int main(){
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  while (_c[ptr]) {
      ++ptr;
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++ptr;
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++ptr;
      ++_c[ptr];
      ++_c[ptr];
      ++_c[ptr];
      ++ptr;
      ++_c[ptr];
      --ptr;
      --ptr;
      --ptr;
      --ptr;
      --_c[ptr];
  }
  ++ptr;
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  ++ptr;
  ++_c[ptr];
  putchar(_c[ptr]);
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  putchar(_c[ptr]);
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  ++ptr;
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  --ptr;
  --ptr;
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  ++ptr;
  putchar(_c[ptr]);
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  putchar(_c[ptr]);
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  --_c[ptr];
  putchar(_c[ptr]);
  ++ptr;
  ++_c[ptr];
  putchar(_c[ptr]);
  ++ptr;
  putchar(_c[ptr]);
  ++_c[ptr];
  ++_c[ptr];
  ++_c[ptr];
  putchar(_c[ptr]);
  return 0;
  }
  </code></pre>
  
  <p>Script in Ruby:</p>
  
  <pre><code>require 'shellwords'
  
  code = ""
  
  loop do
      x = gets.chomp
      break if x=="__END__"
      code &lt;&lt; x
  end
  
  code_arr = []
  
  code.split("").each {|ch|
      case ch
      when "&gt;";code_arr &lt;&lt; "++ptr;"
      when "&lt;";code_arr &lt;&lt; "--ptr;"
      when "+";code_arr &lt;&lt; "++_c[ptr];"
      when "-";code_arr &lt;&lt; "--_c[ptr];"
      when ".";code_arr &lt;&lt; "putchar(_c[ptr]);"
      when ",";code_arr &lt;&lt; "_c[ptr] = getchar();"
      when "[";code_arr &lt;&lt; "while (_c[ptr]) {"
      when "]";code_arr &lt;&lt; "}"
      end
  }
  
  filename = "main"
  
  sp = ""
  
  ostr = "#include &lt;stdio.h&gt;\nunsigned char _c[30000]={};#{sp}int ptr=0;#{sp}int main(){#{code_arr.join(sp)+sp}return 0;#{sp}}"
  File.open("#{filename}.c","w").write(ostr)
  puts ostr
  result = system("gcc -Wall #{filename}.c -o ./#{filename}")
  puts "Process exited with code #{result}"
  </code></pre>