eclipse-cdt / cdt

Eclipse CDT™ C/C++ Development Tools
http://eclipse.org/cdt
Eclipse Public License 2.0
309 stars 201 forks source link

Type std:: and other libiraries cannot be resolved #905

Open ENate opened 2 months ago

ENate commented 2 months ago

Describe the bug I am unable to access std::cout, std::string and similar C** libraries on Eclipse. When I open or create a new CMake (Makefile) project on eclipse C++, may of these libraries are not detected. I usually see the following error:

Description
Type 'std::error_code' could not be resolved    
Type std

To Reproduce Steps to reproduce the behavior:

  1. Create or open a C** project
  2. Add or use one of the std libs (e.g std::string, etc)'
  3. See error

Expected behavior A clear and concise description of what you expected to happen. I will expect that C++ libs and language server can automatically be picked up and code assist work normally. Screenshots If applicable, add screenshots to help explain your problem.

Version Information (please complete the following information):

Additional context Add any other context about the problem here. For example the error log (in workspace/.metadata/.log) or for GDB interaction issues the GDB traces

i-garrison commented 1 month ago

Do not forget to include required headers, also some important c++20 features are not implemented and you may need to change compiler standard version (like limit to -std=c++17 in built-in compiler settings provider.) Simple std::string code should work fine with c++17 or lower.

ENate commented 1 month ago

Thanks @i-garrison . I added 17in my make files etc. Do you think there is need to include -std=c++17to

${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"

under the Eclipse Preferences->Build->Settings->Discovery? I suppose this will be picked up.

i-garrison commented 1 month ago

Thanks @i-garrison . I added 17in my make files etc. Do you think there is need to include -std=c++17to

${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"

under the Eclipse Preferences->Build->Settings->Discovery? I suppose this will be picked up. You can check value of __cplusplus macro to confirm which C++ standard version you have configured. See Preprocessor includes -> Entries -> CDT GCC Built-in Compiler Settings - may have to reindex project for those to take effect.

ENate commented 1 month ago

I saw __cpluscplus=201703Lunder the option you proposed. I only got to see Preprocessor Includes after selecting the project -> New -> ...Add C++ project Nature. Is this okay?

i-garrison commented 1 month ago

I saw __cpluscplus=201703Lunder the option you proposed. I only got to see Preprocessor Includes after selecting the project -> New -> ...Add C++ project Nature. Is this okay?

Hi @ENate you need to have your c++ project properly configured, so likely yes. Could be easiest to double-check by starting from scratch and selecting e.g. managed c++ build.

ENate commented 1 month ago

Thanks @i-garrison . So does this __cpluscplus=201703L corresponds to C++ 17?

i-garrison commented 1 month ago

Thanks @i-garrison . So does this __cpluscplus=201703L corresponds to C++ 17?

It does, yes. Make sure your source file is recognized as c++ file and all necessary headers are included and resolved (check via indexer -> search for unresolved includes.) IOW it works for me with C++17.

ENate commented 1 month ago

Thanks indeed. This is my first experience with using Eclipse cdT for c++ development.