Gecode编译报错求助:VS2017引入gecode/int.hh出现编译错误
Hey there, let’s work through those three compilation errors you’re hitting when using Gecode 6.0 with VS 2017. These issues are typically tied to compiler compatibility or project configuration mismatches—here’s how to address them step by step:
Possible Causes & Solutions
1. Adjust Your Project’s C++ Standard Version
Gecode 6.0 was released around 2017, and it’s optimized for the C14 standard. VS 2017 might default to a newer standard like C17, which can create conflicts with Gecode’s older template and function definitions.
- Right-click your project → Properties → navigate to C/C++ > Language
- Set C++ Standard to ISO C14 Standard (/std:c14)
- Apply the changes and rebuild your project.
2. Fix the Duplicate Function Definition (Error C2084)
The Gecode::cmb_hash function is being flagged as having multiple definitions, which stems from how MSVC handles inline functions in older codebases. You can modify the Gecode header to resolve this:
- Open
c:\program files\gecode\include\gecode\support\hash.hpp - Locate the
cmb_hashfunction at line 61, which should look like this:inline void cmb_hash(size_t& h, size_t d) { h ^= d + 0x9e3779b9 + (h << 6) + (h >> 2); } - Change
inlinetostaticto ensure the function is only defined once per translation unit:static void cmb_hash(size_t& h, size_t d) { h ^= d + 0x9e3779b9 + (h << 6) + (h >> 2); } - Save the file and rebuild. This should eliminate the C2084 error, and the subsequent C2264 errors from
dfa.hppwill likely disappear too—since they depend on the correct definition ofcmb_hash.
3. Check for Conflicting Macros or Duplicate Includes
Sometimes, other libraries or project settings can define macros that clash with Gecode’s functions:
- Go to Project Properties > C/C++ > Preprocessor > Preprocessor Definitions
- Look for any macros named
cmb_hashor related to hash functions—remove or rename them if found - Double-check that you’re not accidentally including duplicate copies of Gecode headers (e.g., from both the system path and a local project directory)
Final Notes
If these steps don’t fix the issue, verify that you’re using a Gecode build compiled specifically for VS 2017 (matching your MSVC version). Alternatively, consider upgrading to a newer Gecode release if your project allows—newer versions often patch compiler compatibility bugs.
内容的提问来源于stack exchange,提问作者Jakub Pawlak

