CLion cannot find header files in a remote project.
I’m doing remote development in CLion using local sources.
After I correctly configured the remote build environment and completed the first build, I noticed that my local code can’t resolve its own project headers via the search paths, even though system headers and third-party library headers are recognized just fine.
What could be causing this?
For example, for src/include/mempool.h.
My CMakeLists.txt contains:
include_directories(
${PROJECT_BINARY_DIR}/src/include
${PROJECT_SOURCE_DIR}/src)The compile_commands.json generated in the build directory includes -I/tmp/ceph/src. In this example, /tmp is the workspace on the remote server that’s mapped inside the Docker container and kept in sync with the local sources.
After configuring the CMake project, the header search paths do include the src directory, but only the headers from third-party libraries were synchronized; the include directory and its files were not. Given that mempool.h exists in the local sources, this might be expected, but right now CLion also doesn’t attempt to search the local source directory—the suggested search paths all come from .remote.
请先登录再写评论。
Hello!
Does calling Tools | Resync with Remote Hosts help (https://www.jetbrains.com/help/clion/remote-projects-support.html#resync)?
Thanks for your reply Anna Falevskaya
I tried Resync with Remote Hosts multiple times (and cleared the .remote directory before running the command), but I’m getting the same result — third-party and system libraries are synced, but the
src/includedirectory isn’t.I've just realized that you use
${PROJECT_BINARY_DIR}/src/include. Is that intentional? Is thesrc/includedirectory located in the build directory (i.e., next to the resulting binary)?No, I’m not referring to
${PROJECT_BINARY_DIR}/src/include, but to subdirectories likeincludeandcommonunder${PROJECT_SOURCE_DIR}/src.${PROJECT_BINARY_DIR}/src/includeis correctly synced from the build directory and contains some generated header files (e.g.,ver.h).How does
#includelook like in the code? Is it#include “src/include/mempool.h”,#include “include/mempool.h”, or#include “mempool.h”?If you use
#include “include/mempool.h”in the code, is themempool.hfound, or is it marked as not found by CLion?I use like this:
CLion reports that it can’t find the headers in the search paths. All of those search paths come from under
.remote, includingsrc. But as I mentioned earlier, thesrcthere only contains third-party libraries and doesn’t have the headers that already exist in the local source, such asincludeandcommon.That's expected. CLion doesn't copy
includeandcommoninto the.remotedirectory since they already exist locally inside the project.However, the header search paths should contain your local
<local project directory>/srcpath.I checked this setup with the Remote Host toolchain on my side, and it worked fine for me:
If I use a non-existent header name, then it's visible that the header search paths contain the local path to
include:Please open in the editor any file that has
#include “include/mempool.h”, place the caret in the code, do Help | Find Action, search for the Show Compiler Info action there, select it, and provide the “Compiler switches:” and “Header Search paths:” sections from the result of the action.Also, please clarify how you add these third-party libraries to the project and why they end up under
src.Yes, I think that’s reasonable. I’m just puzzled why it isn’t searching the local path.
Here is my Compiler Info:
And the third-party libraries are included in the project as git submodules.
I'd like to clarify your setup. My current understanding is the following:
Is my understanding correct?
It seems that some path mappings don't work correctly, and the
-I/tmp/ceph/srccompiler switch isn't converted into<local project path>/srcin Header Search paths (there is an emptyPointerline). But I don't understand the reason.Have you manually configured any path mappings somewhere in the Docker toolchain?
I meant to ask how they are included in your CMakeLists.txt. Do you use
add_subdirectory()? Or do you not reference these libraries in your CMakeLists.txt at all?Exactly right, and I haven’t manually set any path mappings.
I do use these libraries in CMakeLists.txt. For libraries that support CMake, I use
add_subdirectory; for the others, I specify the search paths withinclude_directoriesand add their source files to the compilation list.MER, so far, we haven't managed to reproduce the issue on our side with a simple project and the Remote Docker toolchain. Please create a sample project with which the issue can be stably reproduced, submit an issue to our tracker https://youtrack.jetbrains.com/issues/CPP, and attach the reproducer and the link to this thread to the issue. Thank you in advance!