C++ 预链接器错误

标签 c++

能否请您告诉我如何处理我在链接过程中看到的以下 2 个错误?

提前致谢。

C++ prelinker: error: std::basic_ostream<T1, T2> &std::basic_ostream<T1, T2>::flush() [with T1=char, T2=std::char_traits<char>] assigned to work\KernelAppComponent_kernel.o and work\KernelAppComponent_kernel.o

C++ prelinker: error: bad instantiation request file -- instantiation assigned to more than one file

ccintppc: Error: C++ prelink operation failed.
Error: build failed

编译器是 GreenHills 的 Multi Compiler for PowerPC architecture and Integrity OS。

好吧,在项目中清理和重建组件之后,那些预链接器错误以某种方式被删除(真的不知道发生了什么)但是引入了以下 Unresolved 符号错误。它只是一个 hello world 程序。有人可以告诉我出了什么问题吗?

Cleaning KernelAppComponent.mod
Building KernelAppComponent.mod
Compiling MainKernelAppComponent.cpp because MainKernelAppComponent.o does not exist
Compiling KernelApp.cpp because KernelApp.o does not exist
Linking KernelAppComponent because it does not exist
Compiling KernelAppComponent_kernel.cc because KernelAppComponent_kernel.o does not exist
Compiling global_table.c because global_table.o does not exist
Linking KernelAppComponent_kernel because it does not exist
C++ prelinker: std::basic_ostream<T1, T2> &std::basic_ostream<T1, T2>::put(T1) [with T1=char, T2=std::char_traits<char>] assigned to file work\KernelAppComponent_kernel.o
C++ prelinker: std::basic_ostream<T1, T2> &std::basic_ostream<T1, T2>::flush() [with T1=char, T2=std::char_traits<char>] assigned to file work\KernelAppComponent_kernel.o
Compiling KernelAppComponent_kernel.cc because reg.h has changed
Compiling global_table.c because reg.h has changed
Linking KernelAppComponent_kernel because KernelAppComponent_kernel.o has changed

[elxr] (error) unresolved symbols: 20
 _main         from KernelAppComponent_kernel.o
 clear__Q2_3std8ios_baseFQ3_3std14_Iosb__tm__2_i8_Iostateb         from KernelAppComponent_kernel.o
 __ghsLockCpp         from KernelAppComponent_kernel.o
 _Id_cnt__Q3_3std6locale2id         from KernelAppComponent_kernel.o
 __ghsUnlockCpp         from KernelAppComponent_kernel.o
 __vtbl__Q2_3std9type_info         from KernelAppComponent_kernel.o
 _Getctyptab         from KernelAppComponent_kernel.o
 _Psave__Q2_3std41_Facetptr__tm__24_Q2_3std14ctype__tm__2_c         from KernelAppComponent_kernel.o
 id__Q2_3std17ctype__tm__2_c__S         from KernelAppComponent_kernel.o
 _Getfacet__Q2_3std6localeCFUi         from KernelAppComponent_kernel.o
 __nw__FUi         from KernelAppComponent_kernel.o
 __ct__Q2_3std8_LocinfoFPCc         from KernelAppComponent_kernel.o
 __dt__Q2_3std8_LocinfoFv         from KernelAppComponent_kernel.o
 _Register__Q3_3std6locale5facetFv         from KernelAppComponent_kernel.o
 cout__3std         from KernelAppComponent_kernel.o
 __dl__FPv         from KernelAppComponent_kernel.o
 __dla__FPv         from KernelAppComponent_kernel.o
 __ct__Q3_3std8ios_base4InitFv         from KernelAppComponent_kernel.o
 __record_needed_destruction         from KernelAppComponent_kernel.o
 __dt__Q3_3std8ios_base4InitFv         from KernelAppComponent_kernel.o

[elxr] (error) errors during processing
Error: build failed
Build failed (Tue Jul 01 10:48:23 2008)

最佳答案

我在使用 Green Hills Multi 编译器时多次看到这种错误。作为Rup's comment指出,这是由于模板代码在 2 个(或更多)目标文件中为相同的具体类实例化,导致链接时出错。我认为我在进行干净构建时从未见过这种情况,所以这似乎只发生在重新编译部分文件子集后重新链接项目时。
这是有道理的:在最初的完整构建期间,模板实例化 T 与对象文件 Foo.o 任意关联。后来,Bar.c 被修改,当重新编​​译时,T 也与 Bar.o 相关联。然后您会收到链接错误。

我很久以前就想出了上面的问题,但一直没有想出如何快速解决它。 (我经常不得不求助于恢复到干净的构建。)但现在在阅读了 AProgrammer's answer 之后,我很高兴地报告,删除相应的 .ii 文件确实解决了问题。

通常,如果您收到链接错误,例如

C++ prelinker: error: std::basic_ostream<T1, T2> &std::basic_ostream<T1, T2>::flush() [with T1=char, T2=std::char_traits<char>] assigned to path\to\Foo.o and another\path\to\Bar.o

然后要解决错误,请删除 path\to\Foo.ii 处的相应 .ii 文件和 another\path\to\Bar.ii ,分别尝试再次链接。请注意,您可能仍会遇到另一组冲突,因此您可能需要在链接最终完成之前重复该循环几次。

(请注意,在OP's original question中,两个路径是相同的,所以Rob Kennedy stated,这种特殊情况可能是由于项目文件错误,例如在编译列表中有两次相同的源文件目标或在链接目标列表中有两次相同的目标文件。)

关于C++ 预链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5234183/

相关文章:

javascript - 为 asm.js 编写优化的 JS

c++ - 绑定(bind)到 OpenGL 3.x VBO

c++ - 从 C++ 中的类成员函数返回对象

c++ - 模板参数推导/替换失败,lambda 作为函数指针

c++ - 字符串函数的返回值

C++ 输入输出排序

php - 使用 zlib 在 C++ 和 PHP 之间移动压缩字符串

c++ - 将 const 放在标题中

c++ - 在 Linux 上监视目录的程序

c++ - 使用 Qt 编辑 VBulletin 帖子