title: Undefined Symbols for Architecture x86-64"start"
body: <p>How can I link my program?</p>
  
  <p>I have a mid 2012 macbook pro which I recently upgraded to OSX 10.11 (El Capitan). In order to compile c++ programs I had to reinstall g++ which I did using brew.</p>
  
  <p>Now I am getting an error when trying to link my program.</p>
  
  <blockquote>
    <p>g++-6 -o hello hello.o</p>
    
    <p>Undefined symbols for architecture x86_64:
      "start", referenced from:
         implicit entry/start for main executable
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status</p>
  </blockquote>
  
  <p>Here is my code: hello.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main(){
      std::cout&lt;&lt;"Beginning program";
      return 0;
  }
  </code></pre>
  
  <p>And this is the output when I link with the -v flag</p>
  
  <blockquote>
    <p>g++-6 -o hello hello.o -v</p>
  </blockquote>
  
  <p>Using built-in specs.</p>
  
  <p>COLLECT_GCC=g++-6</p>
  
  <p>COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/lto-wrapper</p>
  
  <p>Target: x86_64-apple-darwin15.6.0</p>
  
  <p>Configured with: ../configure --build=x86_64-apple-darwin15.6.0 --prefix=/usr/local/Cellar/gcc/6.2.0 --libdir=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 6.2.0' --with-bugurl=<a href="https://github.com/Homebrew/homebrew/issues" rel="nofollow">https://github.com/Homebrew/homebrew/issues</a> --enable-plugin --disable-nls --enable-multilib</p>
  
  <p>Thread model: posix</p>
  
  <p>gcc version 6.2.0 (Homebrew gcc 6.2.0) </p>
  
  <p>COMPILER_PATH=/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/</p>
  
  <p>LIBRARY_PATH=/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/:/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../../</p>
  
  <p>COLLECT_GCC_OPTIONS='-o' 'hello' '-v' '-mmacosx-version-min=10.11.3' '-shared-libgcc' '-mtune=core2'
   /usr/local/Cellar/gcc/6.2.0/libexec/gcc/x86_64-apple-darwin15.6.0/6.2.0/collect2 -dynamic -arch x86_64 -macosx_version_min 10.11.3 -weak_reference_mismatches non-weak -o hello -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../.. hello.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
  collect2 version 6.2.0
  /usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.11.3 -weak_reference_mismatches non-weak -o hello -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0 -L/usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0/../../.. hello.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
  @(#)PROGRAM:ld  PROJECT:ld64-136
  configured to support archs: armv6 armv7 armv7s i386 x86_64</p>
  
  <p>Library search paths:
      /usr/local/Cellar/gcc/6.2.0/lib/gcc/6/gcc/x86_64-apple-darwin15.6.0/6.2.0
      /usr/local/Cellar/gcc/6.2.0/lib/gcc/6
      /usr/lib
      /usr/local/lib</p>
  
  <p>Framework search paths:
      /Library/Frameworks/
      /System/Library/Frameworks/</p>
  
  <p>Undefined symbols for architecture x86_64:
    "start", referenced from:
       implicit entry/start for main executable
  ld: symbol(s) not found for architecture x86_64
  collect2: error: ld returned 1 exit status</p>
  
  <p>I've read from other posts that this might be a problem with the default libraries being compiled by an older version of g++. But I think that isn't the problem here because the library search paths seem to point g++ towards g++-6's libraries. </p>