Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Wrong working directory leading to clang errors #61

Closed
nafur opened this issue May 26, 2015 · 4 comments
Closed

Wrong working directory leading to clang errors #61

nafur opened this issue May 26, 2015 · 4 comments
Labels

Comments

@nafur
Copy link

nafur commented May 26, 2015

When I try to autocomplete in a file (say /home/user/project/test.h), the clang commandline looks like this:

clang++ -fsyntax-only -xc++ -Xclang -code-completion-at=-:97:19 -std=c++11 -I. -std=c++11 -working-directory=/home/user -

In my case, the file contains an include to another file in the same folder.
However, due to -working-directory=/home/user, clang is unable to locate this file.

@nafur
Copy link
Author

nafur commented Aug 26, 2015

I'd really like to use this plugin, but this error persists.
I tried to craft a patch fixing this bug, which turned out to basically remove the try block in buildClangArgs.

However, I hit another problem then: When completing in a header file, clang complains about having #pragma once in the main file and refuses to give any completions.
This can be fixed by using echo "#include \"filename.h\"" | clang++ instead of cat filename.h | clang++, i.e. simply changing the input option in codeCompletionAt().
This however requires that the file is actually saved before performing autocompletion...

@neocturne
Copy link

I've just looked into this, as I'm affected this bug as well. The issue lies in the "clang-flags" package, which always adds a -working-directory=#{searchDir} parameter to the clang call, where searchDir is the directory of the .clang_complete file. I think this should be fixed in clang-flags, but workarounding it in autocomplete-clang would also be easy.

@neocturne
Copy link

I've opened Kev/clang-flags#11 . In the mean time, the following fixes the issue for me:

diff --git a/lib/clang-provider.coffee b/lib/clang-provider.coffee
index 2fe6064..09d6066 100644
--- a/lib/clang-provider.coffee
+++ b/lib/clang-provider.coffee
@@ -35,6 +35,7 @@ class ClangProvider
     options =
       cwd: path.dirname(editor.getPath())
       input: editor.getText()
+    args.push("-working-directory=#{options.cwd}")

     new Promise (resolve) =>
       allOutput = []

@stale
Copy link

stale bot commented Jun 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 17, 2019
@stale stale bot closed this as completed Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants