![](/img/trans.png)
[英]How to display C++ Boost Library multi-precision big integers in binary form?
[英]Can't figure out why multi-precision calculation doesn't work for me using boost library
首先,我嘗試使用GMP,因為boost文檔說它更快,但是boost庫中缺少gmp.h文件,因此我必須安裝GMP庫並復制gmp.h。 這樣做之后,使用mpz_int時出現外部符號錯誤。 因此,我決定嘗試使用cpp_int,從boost文檔中復制該示例,然后它起作用了。 這是我嘗試的:
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
int main()
{
using namespace boost::multiprecision;
int128_t v = 1;
// Do some fixed precision arithmetic:
for(unsigned i = 1; i <= 20; ++i)
v *= i;
std::cout << v << std::endl; // prints 20!
// Repeat at arbitrary precision:
cpp_int u = 1;
for(unsigned i = 1; i <= 100; ++i)
u *= i;
std::cout << u << std::endl; // prints 100!
return 0;
}
因此,然后我在Math類中創建了階乘函數,但是現在每次使用cpp_int庫中的變量時,都會收到該錯誤:錯誤LNK2019:函數“ void __cdecl std :: _ Debug_message(wchar_t const *,wchar_t)中引用的未解析的外部符號__CrtDbgReportW const *,unsigned int)”(?_Debug_message @ std @@ YAXPB_W0I @ Z)
現在,每次我嘗試為cpp_int變量分配一個新值時,都會收到該錯誤,奇怪的是,該示例正常工作,而現在該示例不適用於該項目,但是如果我創建一個新項目並使用相同的項目boost lib它再次起作用。
您正在使用的庫之一(可能是cpp_int庫)可能要與Visual Studio運行時庫的Debug版本鏈接。 (符號__CrtDbgReportW
僅在VS運行時庫的Debug版本中定義。)
確保為適當的目標(調試/發布)編譯代碼,為相同的目標編譯使用的第三方庫,並與相應的運行時庫鏈接。
編輯(在您之前添加的評論之后):
確保為VC運行時庫的靜態 調試版本(aka libcpmtd.lib
)編譯代碼:
在Visual Studio中,打開“項目屬性”對話框,然后在“ Configuration Properties
->“ C/C++
-> Code Generation
,將“ Runtime Library
字段設置為: Multi-threaded Debug (/MTd)
。
請注意,您鏈接到構建的任何其他庫都必須具有相同的設置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.