草庐IT

c++ - Link Error : xxx is already defined in *****.LIB::究竟是什么错误?

coder 2024-02-10 原文

问题:

我正在尝试使用名为 DCMTK 的库它使用了一些其他外部库(zlib、libtiff、libpng、libxml2、libiconv)。我从同一网站下载了这些外部库(*.LIB 和 *.h 文件)。现在,当我编译 DCMTK 库时,出现如下链接错误(793 错误):

Error   2   error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
Error   3   error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
Error   4   error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll)  LIBCMTD.lib dcmmkdir 
Error   5   error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib dcmmkdir 
Error   6   error LNK2005: __errno already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib dcmmkdir 
Error   7   error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)    LIBCMTD.lib dcmmkdir 
Error   8   error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)   LIBCMTD.lib dcmmkdir 

文档:

这似乎是该库的一个常见错误,因此,他们确实有一个解决此问题的常见问题解答条目,其中 ( http://forum.dcmtk.org/viewtopic.php?t=35) 说:

  • The problem is that the linker tries to combine different, incompatible versions of the Visual C++ runtime library into a single binary.
  • This happens when not all parts of your project and the libraries you link against are generated with the same code generation options in Visual C++.
  • Do not use the /NODEFAULTLIB workaround, because strange software crashes may follow. Fix the problem!

  • DCMTK is by default compiled with the "Multithreaded" or "Multithreaded Debug" code generation option (the latter for Debug mode).

  • Either change the project settings of all of your code to use these code generation options,
  • or change the code generation for all DCMTK modules and re-compile.
  • MFC users beware: DCMTK should be compiled with "Multithreaded DLL" or "Multithreaded DLL Debug" settings if you want to link the libraries into an MFC application.

其他人相同问题的解决方案:

Huge Amount of Linker Issues with Release Build Only说:

It seems that your release build is trying to link to something that was built debug. You probably have a broken dependency in your build, (or you missed rebuilding something to release by hand if your project is normally built in pieces).

More technically, you seem to be linking projects built with different C Run Time library settings, one with "Multi-Threaded", another one with "Multi-Threaded Debug". Adjust the settings for all the projects to use the very same flavour of the library and the issue should go away

问题:

直到现在,我一直认为名称修改是唯一可能导致链接失败的问题,如果它没有被标准化的话。刚才我知道还有其他事情也可以导致同样的效果。

  1. “ Debug模式”(多线程调试)和“ Release模式”(多线程)是怎么回事? 到底背后发生了什么?为什么正是这个东西导致链接错误?

  2. 我想知道是否有一种叫做“单线程调试”和“单线程”的东西再次导致同样的事情。

  3. 文档讨论了有关“代码生成选项”的内容。什么代码生成选项?他们是什么?

  4. 文档特别警告我们不要使用/NODEFAULTLIB 解决方法。 (例如/NODEFAULTLIB :msvcrt )。为什么?我怎么会惹是生非?到底是什么?

  5. 请为 MFC 用户解释文档中的最后一点。因为我稍后将在这个项目中使用 MFC。解释我们为什么要这样做?不做会有什么麻烦。
  6. 还有什么想说的吗?我的意思是关于类似的错误。我对链接器及其问题非常感兴趣。所以,如果有任何类似的事情,你可以提及它们或至少一些关键字。

最佳答案

Whats up with the "Debug Mode" (Multi-Threaded Debug) and "Release Mode" (Multi-Threaded)? What exactly is happening under the hood? Why exactly this thing is causing linking error?

链接器由于多种原因拖入库。最简单的是在链接器命令行上列出一个库,或者在链接器命令行上的链接器应答文件中。但是任何目标文件,无论是在您的项目中编译还是打包到库中,也可以包含 linker options包括请求链接特定的库。事实上,Visual C++ 编译器会自动嵌入与您在编译时使用的项目选项相匹配的链接器选项。

在链接时,来自所有目标文件和静态库文件中的对象的所有链接器选项被合并。如果请求了多个 CRT 库文件名,链接器会读入所有文件名,并且会出现命名冲突,链接器不知道要使用哪一个。

I wonder if there is something called "Single-Threaded Debug" and "Single-Threaded" which again causes the same thing.

曾经有,但最近几个版本的 Visual C++ 只提供了多线程兼容库。

Documentation talks something about "Code Generation Options". What Code Generation Options? WTH are they?

inside your project options .

Documentation specifically warns us not to use /NODEFAULTLIB workaround. (example /NODEFAULTLIB :msvcrt ). Why? How would I cause troubles? what exactly is it?

如果您使用/NODEFAULTLIB,所有存储在目标文件和库中的对象中的链接器设置都会被忽略。您最终将没有运行时库,并且可能会丢失其他库。您可以手动将它们添加回去,但这仍然是一团糟。

Please explain the last point in the documentation for MFC users. Because I'm going to use MFC later in this project. Explain Why should we do it? What troubles would it cause if I don't. Anything more you'd like to mention? I mean regarding similar errors. I'm very interested in Linker & its problems. So, if there are any similar things you can mentions them or some keywords atleast.

MFC 应用程序和 MFC 库必须使用相同的内存管理函数,以便应用程序可以释放 MFC 分配的内存,反之亦然。文件句柄和其他资源也是共享的。 MFC DLL 已编译为在 DLL 中使用 CRT,为了能够共享资源,您需要使用相同的 CRT,这意味着也要使用 DLL。

关于c++ - Link Error : xxx is already defined in *****.LIB::究竟是什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2725815/

有关c++ - Link Error : xxx is already defined in *****.LIB::究竟是什么错误?的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  3. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  4. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  5. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  6. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

  7. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  8. ruby - ruby 中的 TOPLEVEL_BINDING 是什么? - 2

    它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput

  9. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  10. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

随机推荐