无法调试我的c ++程序:错误LNK2038:检测到不匹配

时间:2013-01-02 06:30:23

标签: visual-studio-2010 visual-c++ gmp

我刚刚安装了MPIR库。我已经测试过该程序可以在空代码中看到头文件,如下所示:

#include <iostream>
#include <conio.h>
using namespace std;

#pragma warning(disable: 4800)
#include <mpirxx.h>
#pragma warning(default: 4800)

int main (int argc, char *argv[])
{   
  mpz_class aBigPO2;

  aBigPO2 = 1073741824; //2^30
  aBigPO2*=aBigPO2; //2^60
  aBigPO2*=aBigPO2; //2^120
  aBigPO2*=aBigPO2; //2^240
  aBigPO2*=aBigPO2; //2^480
  aBigPO2*=aBigPO2; //2^960
  aBigPO2*=aBigPO2; //2^1920 
 // cout << aBigPO2 << endl;

cout<<"Hello World";
getch();
}

我尝试编译和调试上面的代码,它工作正常,我可以看到Hello World语句。但是,当我删除cout << aBigPO2 << endl;语句中的注释时,我只在调试时遇到以下错误(当我编译时,它没有显示任何错误)

1>InitializeBuildStatus:
1>  Touching "Debug\gcdgmp.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>mpirxx.lib(osmpz.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Main.obj
1>mpirxx.lib(osdoprnti.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Main.obj
1>mpirxx.lib(osfuns.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Main.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __int64 __thiscall std::ios_base::width(__int64)" (?width@ios_base@std@@QAE_J_J@Z) already defined in mpirxx.lib(osfuns.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in mpirxx.lib(osfuns.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __int64 __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBE_JXZ) already defined in mpirxx.lib(osfuns.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in mpirxx.lib(osdoprnti.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in mpirxx.lib(osdoprnti.obj)
1>c:\users\myuser\documents\visual studio 2010\Projects\gcdgmp\Debug\gcdgmp.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.14
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我该怎么办?

2 个答案:

答案 0 :(得分:0)

CPP中字符串文字的最大长度为16,384(16K)字节。你检查过(2 ^ 1920 = 9.49711451 x 10577)是否属于这个范围吗?

答案 1 :(得分:0)

尝试在#include中添加mpir.h并查看是否可以修复它。