title: OSX/Darwin unresolved symbols when linking functions from <math.h>
body: <p>I'm in the process of porting a large'ish (~1M LOC) project from a Window/Visual Studio environment to other platforms, the first of which happens to be Mac OS X. </p>
  
  <p>Originally the project was configured as Visual Studio solutions and projects, but now I'm using (the excellent) Premake (<a href="http://industriousone.com/premake" rel="nofollow noreferrer">http://industriousone.com/premake</a>) to generate project files for multiple platforms (VS, XCode, GMake).</p>
  
  <p>I configured, ported and built the first few projects without any significant problems, but having ported the math lib, I ran into this weird linking error that I haven't been able to resolve: <strong>Any functions used from math.h will fail to link (causing unresolved symbols).</strong></p>
  
  <p>For reference, I'm using Premake v4.2.1 to generate projects for XCode v3.2.1, which is building using gcc v4.2 for the x86_64 architecture. (All this on 64-bit Snow Leopard) I've tried to persuade gcc to link and build everything against a 'known' SDK by adding -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 to the build command line.</p>
  
  <p>Now under normal circumstances, adding -lm should take care of this, however in Darwin, those math libs are included in libSystem, which, as far as I can tell, gets implicitly linked by gcc/ld. </p>
  
  <p>I've tried creating a dummy project from within XCode which just runs:</p>
  
  <pre><code>float f = log2(2.0)+log2f(3.f)+log1p(1.1)+log1pf(1.2f)+sin(8.0);
  std::cout &lt;&lt; f &lt;&lt; std::endl;
  </code></pre>
  
  <p>and as expected, this builds just fine. However, if I put the same thing in the code inside the Premake generated project, all those math functions end up unresolved.</p>
  
  <p>Now comparing the linking command from the 'native' XCode project with my generated XCode project, they seem pretty identical (except that my generated project links other libs as well).</p>
  
  <p>'Native' project:</p>
  
  <pre><code>/Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -isysroot /Developer/SDKs/MacOSX10.6.sdk -Lsomepath -Fsomepath -filelist somefile -install_name somename -mmacosx-version-min=10.6 -single_module -compatibility_version 1 -current_version 1 -o somename
  </code></pre>
  
  <p>Generated project:</p>
  
  <pre><code>/Developer/usr/bin/g++-4.2 -arch x86_64 -dynamiclib -Lsomepath -Fsomepath -filelist somefile -install_name somename -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 somelib.a somelib2.a somelib.dylib somelib2.dylib -single_module -compatibility_version 1 -current_version 1 -o somename
  </code></pre>
  
  <p>Any help or hints about how to proceed would be most appreciated. Are there any gcc flags or other tools that can help me resolve this?</p>