首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C >> 關於C

解決 Boost string.hpp 引發的 __int64 重複定義編譯錯誤

     編輯:關於C

問題現象

在 Windows 平台使用 MSVC 編譯包含 <boost/algorithm/string.hpp> 的專案時,出現錯誤:

error C2632: '__int64' followed by '__int64' is illegal

原因分析

  1. MSVC 標頭 cstdint.h (或 Windows SDK) 已定義 int64_t 為 __int64。
  2. Boost cstdint.hpp 內部又嘗試 typedef __int64 int64_t;。
  3. 導致同一編譯單元中 __int64 被重複 typedef,觸發 C2632。

解決方案

在包含 Boost 標頭**之前**,先取消定義衝突的巨集/型別:

#undef int64_t
#include <boost/algorithm/string.hpp>

替代方案 (視專案配置)

  • 專案屬性 → C/C++ → Preprocessor → Preprocessor Definitions 加入 BOOST_HAS_STDINT_H (告知 Boost 使用系統 <stdint.h>)。
  • 升級 Boost 版本 (1.55+ 已改善此問題)。
  • 確保專案統一使用 <cstdint> (C++11) 而非手動定義整數型別。

驗證

加入 #undef int64_t 後重新編譯,錯誤消失,專案正常建置。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved