问题
First of all, I know about the -std=c++11 flag to enable c++11 support and where to place it. I've appended -std=c++11
to Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags
and compiling just works fine. But the indexer doesn't get along, for example if I want to use the emplace
function of std::map
(c++11), it will not find the emplace function.
#include <map>
int main() {
std::map<int, int> data;
data.emplace(5,5);
I've also checked out these related questions:
- Eclipse CDT indexer does not know C++11 containers
- Enable C++11 in Eclipse CDT (Juno/Kepler/Luna) indexer
- http://www.eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018
Update: Now that I've played around it even doesn't recognize the std::map type, although compiling fine and eclipse finding all headers...
- Compiler Mingw64 GCC 5.2.0
- Eclipse Mars 4.5
- CDT 8.7
回答1:
Eclipse Mars does it a bit differently than the previous versions.
Step one gets the indexer error highlighting working - covered in Enable C++11 in Eclipse CDT (Juno/Kepler/Luna) indexer linked above. If you've already done all this, I'll be smurfed if I know what you've run into. Mars has been a bit wonky so far.
- Go to Project->properties->C/C++ General->Preprocessor Include Paths.
- Click the Providers tab.
- Click CDT GCC Built-in Compiler settings MinGW
- Click Move Up button on the right.
- Under Language Settings Provider Options
- Click off Use Global provider shared between projects
- Add -std=c++1y to the end of the command line in Command to get compiler specs.
By the way, if anyone knows where the global settings are so I can default this behaviour, please let me know.
Step 2 gets the compiler working
- Go to Project->properties->C/C++ Build->Settings.
- Go to Tool Settings tab.
- Expand GCC C++ Compiler
- Click Dialect Pick the C++ Standard you wish to target from the Language Standard drop-down.
回答2:
Eclipse CDT understands the C++ code in a window by running it through an indexer. This indexer is nothing but an invocation of the GCC C++ compiler with certain compilation options. Sometimes, you might want to change the compiler options used by this indexer.
For example, I recently found that C++11 containers and classes (like future) were not resolved by the indexer and were underlined with red squiggles. This is because the compiler options used by the indexer does not have -std=c++11.
To change the compiler options of the indexer:
- Open Preferences and go to C/C++ -> Build -> Settings.
- Click the Discovery tab and choose CDT GCC Built-in Compiler Settings.
- Modify the command string shown below it as you wish. For example, here I added -std=c++11.
- Eclipse CDT will automatically re-index your C++ files after this is saved. However, I found that this did not remove the unresolved items.
- I manually re-indexed by right-clicking the project and choosing Index -> Rebuild. This worked!
来源:https://stackoverflow.com/questions/32642375/eclipse-cdt-indexer-does-not-fully-recognize-c11