链接器失败:存档中的成员不是对象

时间:2014-10-01 07:21:04

标签: c++ linker makefile g++ mingw

我正在尝试在Windows 7上使用64位mingw构建Open CASCADE(6.7.1)库(我正在使用 x86_64-4.9.1-release-posix-seh-rt_v3-rev1 mingw-w64 project)。

当谈到链接时,它会因错误而失败,我不知道可能出现什么问题。 cmake生成的链接器命令是:

"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 

产生的错误:

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

这是文件的编译方式:

Building CXX object TKernel/CMakeFiles/TKernel.dir/__/__/src/FSD/FSD_BinaryFile.cxx.obj
cd /d TKernel && 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

如果我使用objects.a检查nm文件,内容为.obj,但“文件格式无法识别”看起来不太好...但不知道是什么这究竟意味着......

$ 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
...

file命令的输出:

$ 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

我还尝试从链接器命令中删除--whole-archive选项,但这会导致另一个错误:

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

如果我在文件上运行ranlib,它没有帮助。

任何想法都表示赞赏。

编辑:好的,我猜这个问题是由-MM标志引起的,用于构建。因此,如果我理解正确的话,它并没有真正编译文件。

然而,我找到了OCE项目,这是OCC的某种社区版本,它已经准备好了,所以我将使用该版本,看看它是怎么回事......

0 个答案:

没有答案