Open ikirill opened 9 years ago
Doesn't happen for me. :/
Can you check that the proper checker is used even if it looks like your code set it properly: M-x flycheck-list-errors RET
and see if the checker is really irony.
I do not really recommend using irony-additional-clang-options
but for now I guess there is no better alternative. Ideally a fallback compilation database could exists that specifies these flags, that would be better but that's another subject.
You are on Mac OS X, I'm wondering if there is not some kind of issues with the standard library picked. What if you provide additional arguments such as -stdlib=libc++
?
My libclang came with xcode, and the problem was that it could not find c++ headers. Cmake found libclang headers in /usr/local/include
(they don't come with xcode, so I installed them separately), but libclang needs also to be told where xcode clang headers live
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
because cmake does not seem to pick up that path with find_package(LibClang)
.
This is irritating, but not flycheck-irony's fault. If I invoke clang with -###
to see what flags libclang should use, clang is invoked with
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
This is a related bug, I think: https://github.com/Sarcasm/irony-mode/issues/138
What's interesting is that the completion code doesn't check for diagnostics, and just fails silently on errors like 'vector' file not found
or undeclared identifier 'std'
, failing to suggest any c++ completions.
My libclang came with xcode, and the problem was that it could not find c++ headers. Cmake found libclang headers in /usr/local/include (they don't come with xcode, so I installed them separately), but libclang needs also to be told where xcode clang headers live
I think it would be better to copy the whole clang-related stuff from the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/ prefix and put it somewhere else. Then tell irony-mode -DCMAKE_PREFIX_PATH=<libclang-prefix>
. This could avoid some of the issues but I'm not sure that it will solves everything.
Or you sure you wanted this compile options?
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
Wouldn't the following be better?
-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/ [-stdlib=libc++]
Maybe you would be better of using and "portable release": http://llvm.org/releases/download.html And then maybe install libc++ separately if you don't have a proper libc++ installed? Re-using the XCode
What's interesting is that the completion code doesn't check for diagnostics, and just fails silently on errors like 'vector' file not found or undeclared identifier 'std', failing to suggest any c++ completions.
This may be fixed in the future. I implemented completion before diagnostics, at this time I wasn't sure what to do with the completion diagnostics. Now that I have implemented diagnostics I will be able to use the one provided by code completion. This will require some changes in the way the requests are made to the irony-server, this is something I'm thinking about but I haven't get around yet.
Little question regarding this question. How can I activate C++11? besides using the irony-additional-clang-options
.
It depends, what do you want, just to have -std=c++11
if no compilation database is setup, or do you want to overlay the compile options by adding -std=c++11
automatically?
I would like overlay the compilation options. But it would be nice to know both anyway ;)
For overlay, irony-additional-clang-options
is the way to go.
For fallback options, I provide it in irony-mode but user can already do it in their config, see discussion here: https://github.com/Sarcasm/irony-mode/issues/245#issuecomment-150960367
Thanks for the fast answer. Look, I'm actually put an example with one function std::stod
which is supposed to be working with c++11 according to the stod documentation. I set, for example with M-: irony-additional-clang-options "-std=c++11"
, I reload the options just in case with irony-cdb-autosetup-compile-options
and this is what I get:
Still the same error. One (maybe foolish and naive) thing I did was to add set(CMAKE_CXX_COMPILER_ARG1 -std=c++11)
to the CMakeLists.txt
of irony-mode
, and then recompile it, it didn't work either.
Try: M-: (setq irony-additional-clang-options '("-std=c++11"))
In the end it was apparently working but I did have some problem. Anyway, so, if I want to load it automatically for all my c files I add (setq irony-additional-clang-options '("-std=c++11"))
to my .emacs file and that should be it, correct?
Yes it should be.
thanks again ;)
The problem is with Xcode-specific includes. Even Apple-own libclang.dylib doesn't know of them. I could compile irony-server with standard osx libclang.dylib by grabbing headers from llvm 3.8, yet it did not work properly until the following includes were added into .clang_complete file.
Peek at what Apple compiler uses
echo | clang -x c++ -v -E - 2>&1 | sed -n '/^#include </,/^End/s|^[^/]*\([^ ]*/include[^ ]*\).*$|-I\1|p'
Add them to your .clang_complete:
$ cat .clang_complete
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include
...
In this file (with flycheck-irony installed from melpa in a sandboxed emacs version 25.0.50)
flycheck-irony says
no member named 'function'...
, which is wrong, because if I understand the documentation correctly it should be using-std=c++11
. (On the command lineclang -x c++
does not even need-std=c++11
.)Clang version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)