title: Linker fail: member in archive is not an object
body: <p>I'm trying to build Open CASCADE (6.7.1) library with 64bit mingw on Windows 7 (I am using <em>x86_64-4.9.1-release-posix-seh-rt_v3-rev1</em> from <a href="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.1/threads-posix/seh/" rel="nofollow">mingw-w64 project</a>).</p>
  
  <p>When it comes to linking, it fails with an error and I have no idea what could be wrong. The linker command generated by cmake is:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>"C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\TKernel.dir/objects.a
  C:\msys64\mingw64\bin\ar.exe cr CMakeFiles\TKernel.dir/objects.a @CMakeFiles\TKernel.dir\objects1.rsp
  C:\msys64\mingw64\bin\g++.exe     -shared -o ..\out\bin\libTKernel.dll -Wl,--out-implib,..\out\lib\libTKernel.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\TKernel.dir/objects.a -Wl,--no-whole-archive  -LC:\msys64\home\user\tcl8.5.16\build  -LC:\msys64\home\user\freetype-2.5.3 -ladvapi32 -lgdi32 -luser32 -lkernel32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
  </code></pre>
  
  <p>And the produced error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Linking CXX shared library ..\out\bin\libTKernel.dll
  CMakeFiles\TKernel.dir/objects.a: member CMakeFiles\TKernel.dir/objects.a(FSD_BinaryFile.cxx.obj) in archive is not an object
  collect2.exe: error: ld returned 1 exit status
  TKernel\CMakeFiles\TKernel.dir\build.make:11422: recipe for target 'out/bin/libTKernel.dll' failed
  </code></pre>
  
  <p>This is how the files are compiled:</p>
  
  <pre class="lang-none prettyprint-override"><code>Building CXX object TKernel/CMakeFiles/TKernel.dir/__/__/src/FSD/FSD_BinaryFile.cxx.obj
  cd /d TKernel &amp;&amp; C:\msys64\mingw64\bin\g++.exe   -DCSFDB -DTKernel_EXPORTS -DWNT -D_OCC64 -D_SCL_SECURE_NO_WARNINGS -MP -Wall -O3 -DNDEBUG -DNo_Exception @CMakeFiles/TKernel.dir/includes_CXX.rsp   -MM -D__FSD_DLL -D__MMgt_DLL -D__OSD_DLL -D__Plugin_DLL -D__Quantity_DLL -D__Resource_DLL -D__SortTools_DLL -D__Standard_DLL -D__StdFail_DLL -D__Storage_DLL -D__TColStd_DLL -D__TCollection_DLL -D__TShort_DLL -D__Units_DLL -D__UnitsAPI_DLL -D__IncludeLibrary_DLL -D__Dico_DLL -D__NCollection_DLL -D__Message_DLL -o CMakeFiles\TKernel.dir\__\__\src\FSD\FSD_BinaryFile.cxx.obj -c ..\..\src\FSD\FSD_BinaryFile.cxx
  </code></pre>
  
  <p>If I check the <code>objects.a</code> file with <code>nm</code>, the contents are <code>.obj</code>, but "File format not recognized" doesn't look good... but don't know what exactly does that mean...</p>
  
  <pre class="lang-none prettyprint-override"><code>$ nm objects.a
  C:\msys64\mingw64\x86_64-w64-mingw32\bin\nm.exe: FSD_BinaryFile.cxx.obj: File format not recognized
  C:\msys64\mingw64\x86_64-w64-mingw32\bin\nm.exe: FSD_CmpFile.cxx.obj: File format not recognized
  ...
  </code></pre>
  
  <p>Output from <code>file</code> command:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ file objects.a
  objects.a: current ar archive
  
  $  file __/__/src/FSD/FSD_BinaryFile.cxx.obj
  __/__/src/FSD/FSD_BinaryFile.cxx.obj: ASCII text, with CRLF line terminators
  </code></pre>
  
  <p>I also tried to remove the <code>--whole-archive</code> option from the linker command, but that leads to another error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Linking CXX shared library ..\out\bin\libTKernel.dll
  CMakeFiles\TKernel.dir/objects.a: error adding symbols: Archive has no index; run ranlib to add one
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  
  <p>If I run ranlib on the file, it doesn't help. </p>
  
  <p>Any ideas are appreciated.</p>
  
  <p><strong>edit:</strong> Ok, so I guess that the problem is caused by -MM flag, that was used for the build. So it didn't really compile the files, if I understand it correctly.</p>
  
  <p>However I found  <a href="https://github.com/tpaviot/oce" rel="nofollow">OCE</a> project, which is some sort of community edition of OCC and it is quite mingw-ready, so I'm gonna use that version and see how it goes...</p>