Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load even simple CMake project into Eclipse CDT #576

Open
bkeys opened this issue Sep 26, 2023 · 18 comments
Open

Unable to load even simple CMake project into Eclipse CDT #576

bkeys opened this issue Sep 26, 2023 · 18 comments

Comments

@bkeys
Copy link

bkeys commented Sep 26, 2023

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Download https://github.com/jameskbride/cmake-hello-world as a simple example
  2. Extract it
  3. Go to File > New > C/C++ Project
  4. Select "Empty or Existing CMake Project"
  5. Fill out the fields as usual, make sure you are using the same directory as the cmake-hello-world example

Expected behavior
To have the build option not greyed out, and to be able to resolve inclusions like #include <iostream>, on my installation it cannot resolve the line using namespace std;.

Screenshots
image

Version Information (please complete the following information):

  • OS and OS Version/extra details: Linux ppc64le Fedora 38

  • Eclipse Version from Help ->
    image

  • CDT Version from Help -> About -> Installation Details -> Features tab [e.g. 10.3.1, 11.2.0]
    image

@jonahgraham
Copy link
Member

To have the build option not greyed out

Try checking if Project -> Build Automatically is checked, and if so uncheck it to enable the build options.

and to be able to resolve inclusions like #include , on my installation it cannot resolve the line using namespace std;.

CMake projects need the build information to resolve, so a first build is needed to collect the include locations from the compile_commands.json

@bkeys
Copy link
Author

bkeys commented Sep 26, 2023

It has no active build configurations (nor the ability to set one), and it's unchecked and is still grey.
Is compile_commands.json generated by the makefile or by Eclipse CDT?
EDIT: I just told it to build the entire project and it got me a compile_commands.json, but it still can't resolve inclusions.

@bkeys
Copy link
Author

bkeys commented Sep 26, 2023

Here is the content of my compile_commands.json, I don't know how this will resolve the inclusions:

[
{
  "directory": "/home/bkeys/Devel/cmake-hello-world-master/build/cmake.debug.linux.ppc64le",
  "command": "/usr/bin/g++  -I/home/bkeys/Devel/cmake-hello-world-master/Hello  -o CMakeFiles/CMakeHelloWorld.dir/HelloWorld.cpp.o -c /home/bkeys/Devel/cmake-hello-world-master/HelloWorld.cpp",
  "file": "/home/bkeys/Devel/cmake-hello-world-master/HelloWorld.cpp",
  "output": "CMakeFiles/CMakeHelloWorld.dir/HelloWorld.cpp.o"
},
{
  "directory": "/home/bkeys/Devel/cmake-hello-world-master/build/cmake.debug.linux.ppc64le/Hello",
  "command": "/usr/bin/g++    -o CMakeFiles/Hello.dir/Speaker.cpp.o -c /home/bkeys/Devel/cmake-hello-world-master/Hello/Speaker.cpp",
  "file": "/home/bkeys/Devel/cmake-hello-world-master/Hello/Speaker.cpp",
  "output": "Hello/CMakeFiles/Hello.dir/Speaker.cpp.o"
}
]```

@jonahgraham
Copy link
Member

I'm not a cmake expert, so not sure where this is failing - sounds like the index isn't refreshing properly once the compile commands are ready. I'll leave it to others in the community to answer those aspects. We have been discussing how to improve cmake integration in #419 FWIW

@ghentschke
Copy link
Contributor

CDT parses the compile_commands.json and determines the compiler settings and include directories. @bkeys : Does it work, when you close the HelloWorld.cpp and reopen it again?

@ghentschke
Copy link
Contributor

ghentschke commented Jan 1, 2024

I just tested it with Eclipse 2023-09 on Windows 10. I've seen the same issue as @bkeys with the old C/C++ Editor. The include/std indexer problem is gone, when using the new LSP based C/C++ Editor, because clangd is able to determine the std library on the system.

The easiest way to import a Cmake project into Eclipse CDT is to the import function:
File > Import > General > Projects from Folder or Archive
Select the containing folder via the Directory... button.
It should be imported as Cmake project.

The user has to add a .clangd configuration file manually in the projects root directory. This ensures that clangd can find the compile_commands.json file to dertermine the compiler and its settings. The .clangd file should contain at least the relative path to the compile_commands.json. E.g.:

CompileFlags:
  # When using clangd update this entry to point at the desired
  # configuration directory to pick up the compile_commands.json
  CompilationDatabase: build/default

I assume that the reason for the problems in the old editor is maybe caused by CDT cannot find the compile_commands.json.

@ghentschke
Copy link
Contributor

I assume that the reason for the problems in the old editor is maybe caused by CDT cannot find the compile_commands.json.

That's not true. The compile_commands.json can be found and the system includes getting parsed.
However I suggest to use the new C/C++ Editor.

@razor5k
Copy link

razor5k commented Jul 31, 2024

I have same Problem with Kubuntu 22.04 and eclipse 2023-06 and 2024-06. If you include a system header like iostream, the inclusion couldn't be resolved.
The project is a simple hello world app with iostream included.
There are 2 folders:
app
build
CMakeLists.txt and main.cpp are in the app folder
cd to the build folder
It's created by cmake with following command:
cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ../app
Import project with eclipse by pressing "File->Import->General->Existing Projects into Workspace". Choose the build directory and confirm.
If you open the main.cpp in the Project explorer via double click to "[Source directory]->main.cpp", then the inclusion couldn't be resolved.

@ghentschke
Copy link
Contributor

@razor5k which C/C++ editor are u using? The old or the new LSP based?
Can the project being build successfully?

@razor5k
Copy link

razor5k commented Jul 31, 2024

It's the old one. The project compiles successfully.

The CMakeLists.txt

cmake_minimum_required(VERSION 3.24)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

add_executable(${PROJECT_NAME} main.cpp)

The main.cpp

#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
    cout << "Hello world" << endl;
    return 0;
}

Additionally I checked C/C++ Editor (LSP) as well. The iostream couldn't be resolved either.

@ghentschke
Copy link
Contributor

Hm, when I create an defualt HelloWorld project with the wizzard: File -> New -> C/C++ Project -> CMake project it works when the project has been build
image
image

Please ensure that the indexer is enabled:
image

Does the template work on your machine?

@razor5k
Copy link

razor5k commented Jul 31, 2024

If I create a CMake project by eclipse, it works but if I import an eclipse project created by CMake, the indexer don't work with system includes. Indexers are enabled.
The project is imported doing following steps: "File->Import->General->Existing Projects into Workspace"
If the project is imported by pressing on ""File->Import->C/C++->Existing Code as Makefile Project" and Linux GCC is chosen, the indexer works properly.

@ghentschke
Copy link
Contributor

ghentschke commented Jul 31, 2024

Does your imported project has a CMake Nature? (Project Properties->Project Natures)

Which natures does it have at all?

@razor5k
Copy link

razor5k commented Jul 31, 2024

The Natures are (ordered)
CDT-Make Nature
Scanner Configuration Nature
C++ Nature
C Nature

@ghentschke
Copy link
Contributor

Can you please try to add the CMake Nature to the imported project and check if this helps?

@razor5k
Copy link

razor5k commented Jul 31, 2024

Unfortunately it doesn't change anything. I don't even know if that's an issue with cmake rather than with eclipse cdt.

@ghentschke
Copy link
Contributor

I think it's an CDT import problem. Maybe it makes sense to implement a CMake project import wizard.

@razor5k
Copy link

razor5k commented Jul 31, 2024

After adding the CMake Nature, following things are happened:
I pressed <CTRL>+B to build and a build error is occured.
After that the CMake Nature has been removed by eclipse
The indexer works now, no unresolved includes are there
After pressing <CTRL>+B again, the project builds now (but without CMake Nature)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants