如何全局修复Eclipse CDT识别_Noreturn关键字的语法错误问题
_Noreturn Keyword Globally I totally get the frustration of having to fix this _Noreturn syntax error project-by-project—let’s dive into proper global solutions that avoid that tedious work, plus explain why those global CDT User Setting Entries are locked.
Global Fix Options
1. Workspace-Wide Preprocessor Definition
This is the simplest approach for applying the fix to all current and future projects in your workspace:
- Open
Window > Preferences > C/C++ > Build > Settings - Switch to the Tool Settings tab, then navigate to your compiler (e.g.,
GCC C Compiler > Preprocessor) - In the Preprocessor definitions box, add
_Noreturn=(the empty definition tricks CDT into ignoring the keyword as an unknown identifier) - Click
Apply and Close - For existing projects, right-click the project >
Properties > C/C++ Build > Settings, then clickConfigure Settings...and select Use workspace settings to inherit the global fix. New projects will pick this up automatically.
2. Custom Toolchain for Editable Global Settings
If you noticed the global CDT User Setting Entries are grayed out and uneditable, that’s because Eclipse locks default toolchain configurations to prevent accidental changes. Here’s how to get around that:
- Go to
Window > Preferences > C/C++ > Build > Toolchains - Select your active toolchain (e.g., GCC) and click
Copyto create a custom, editable version - Name it something like "GCC (Custom _Noreturn Fix)" and click
OK - Now head back to
C/C++ > Build > Settings, select your new custom toolchain - Navigate to
CDT User Setting Entries, clickAdd..., choosePreprocessor Macro, set the name to_Noreturnand leave the value blank - Save the settings, then set this custom toolchain as the default for your workspace (or individual projects)
- All projects using this toolchain will inherit the
_Noreturnfix without per-project config.
3. Indexer Configuration (Ensure C Standard Compliance)
Sometimes CDT’s indexer doesn’t recognize _Noreturn because it’s targeting an older C standard (this keyword was added in C11). Fix this globally:
- Open
Window > Preferences > C/C++ > General > Indexer - Under Preprocessor include paths, macros etc., select
Configure Workspace Settings - In the provider list, select your compiler and click
Edit... - Add the macro
__STDC_VERSION__=201112Lto enforce C11 compliance (or a later version like201710Lfor C17) - Combine this with the
_Noreturn=macro from the first option for full coverage.
Why Global CDT User Setting Entries Are Uneditable
The default toolchains in Eclipse CDT have their settings marked as read-only to maintain stability—modifying them directly could break compatibility across all projects. By creating a copied custom toolchain, you get a fully editable configuration that won’t affect the default system toolchain.
内容的提问来源于stack exchange,提问作者dpi

