Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
905 stars 99 forks source link

Irony seems to ignore compilerflags? #171

Closed Paethon closed 8 years ago

Paethon commented 9 years ago

Hi

When using Irony together with flycheck and company everything seems to be working fine, except that all the compiler flags are ignored.

Specifically I wan't to compile using -std=c++11 but flycheck still complains about constexpr being an unknown type. I can compile the file with clang without problems.

I tried setting the flag using a .clang_complete file (and according to irony-cdb-menu the compile options are correctly set). I also tried using irony-additional-clang-options which also didn't work. It looks like the flags are just being ignored.

Any ideas what would cause this? OS: Ubuntu 12.04 Emacs: 24.3.1 irony: 0.2.0-cvs3 clang: version 3.4-1ubuntu3~precise2 (tags/RELEASE_34/final) (based on LLVM 3.4)

Sarcasm commented 9 years ago

Can you make sure it's not just https://github.com/Sarcasm/irony-mode/issues/159 where the buffer wouldn't have been refreshed after you set up your compile options?

What does M-x irony-cdb-menu RET shows as compile options for your file?

What does M-: (irony--adjust-compile-options) RET return?

What happens if you call ~/.emacs.d/bin/irony-server diagnostics /path/to/buffer, then put these enter these flags to stdin?

$ ~/.emacs.d/bin/irony-server diagnostics /tmp/foo.cpp
-std=c++11
Paethon commented 9 years ago

159 : After setting the compile options I can add other expressions and they are correctly marked by flycheck (as long as it isn't C++11 stuff). So I don't think what I am seeing is the same error?

irony-cdb-menu:
Compilation Database: irony-cdb-clang-complete
  Working Directory: /home/c7031105/Dropbox/programming/cpp/constexpr_rng/
  Compile Options:   -std=c++11
irony--adjust-compile-options
("-x" "c++" "-working-directory" "/home/c7031105/Dropbox/programming/cpp/constexpr_rng/" "-std=c++11")

Calling the irony-server manually and giving -std=c++11 works as it should

Sarcasm commented 9 years ago

Okay, and there is no Chinese character in the file or some other non-ascii characters, or a weird encoding https://github.com/Sarcasm/irony-mode/issues/163

Is it possible that you installed a fairly recent version of Clang on Ubuntu 12.04? For example from http://llvm.org/apt/? And that this version uses a more modern libstdc++ from GCC 4.8 backport but irony-server is linked or uses another libclang version? ldd ~/.emacs.d/bin/irony-server

Paethon commented 9 years ago

No. But it looks like they are using different llvm-libraries. So that might be a problem?

ldd /usr/bin/clang
    linux-vdso.so.1 =>  (0x00007fffd55fe000)
    libLLVM-3.4.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-3.4.so.1 (0x00007fc28ec01000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc28e9e4000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc28e6d7000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc28e4c0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc28e101000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc28dee9000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fc28dce1000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fc28daba000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc28d8b5000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc28d5b9000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fc29092f000)
ldd ~/.emacs.d/bin/irony-server
    linux-vdso.so.1 =>  (0x00007fffa693d000)
    libclang.so => /usr/lib/libclang.so (0x00007ff36c4df000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff36c1d3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff36be13000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff36bbf6000)
    libLLVM-3.0.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-3.0.so.1 (0x00007ff36a47a000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff36a275000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff36a05e000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff369d62000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ff36cf8a000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007ff369b59000)
Sarcasm commented 9 years ago

Yes that's probably that, the llvm 3.0 version of Clang will use the GCC 4.6 or so from Ubuntu Precise. This version of GCC has a STL bundled (libstdc++) that is missing a lot of C++11 features.

You could try to remove the libclang-dev packages from the standard repository and use the one from the llvm 3.4 version instead, if irony-server is the only one using it one your system.

Otherwise you could tell irony-server where to look to find the proper libclang. The way to do this may depends on a few things:

To be sure you could do something along the lines of:

cmake -DLIBCLANG_INCLUDE_DIR=</path/to/llvm-3.4/include/dir> \ # the include directory is the one that contains clang-c/Index.h
    -DLIBCLANG_LIBRARY=</path/to/llvm-3.4/libclang.so> \
    -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
    ~/.emacs.d/irony/build/
Paethon commented 9 years ago

By making a symbolic link to the correct libclang and uninstalling libclang and llvm 3.0 I now get consistent libraries. Unfortunately it is still not working.

ldd /home/c7031105/.emacs.d/irony/bin/irony-server  
        linux-vdso.so.1 =>  (0x00007fffcf6b0000)
    libclang.so => /usr/lib/libclang.so (0x00007f2c5620a000) [/usr/lib/libclang.so -> /usr/lib/llvm-3.4/lib/libclang.so]
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2c55efe000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2c55b3e000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2c55921000)
    libLLVM-3.4.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-3.4.so.1 (0x00007f2c53c26000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2c53a21000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2c5380a000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2c5350e000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f2c57157000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f2c532f6000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f2c530ee000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f2c52ec7000)

But considering that the server is working properly when I call it manually I am not sure if that even was a problem before.

Sarcasm commented 9 years ago

But considering that the server is working properly when I call it manually I am not sure if that even was a problem before.

Right.

Hum,

Does completion works? Are you sure flycheck runs irony's checker and not the clang/c++ default one?

Paethon commented 9 years ago

You are the master of all classes! :) That actually was the problem ... I needed a (require flycheck-irony) before the

(eval-after-load 'flycheck
  '(add-to-list 'flycheck-checkers 'irony))

Maybe that should have been obvious?

Well: it works now.

Thanks for your time.

Sarcasm commented 9 years ago

Great. Well it's not explicitly stated in flycheck-irony configuration: https://github.com/Sarcasm/flycheck-irony#configuration but that is indeed necessary for now, I should probably provide a flycheck-irony-setup function so autoloading will work properly but I don't like to do that because some packages provides -setup functions that have a tendency to do some things I would prefer them not to.

drvink commented 9 years ago

I was having the same problem, but then I found irony-cdb-autosetup-compile-options, and that seems to have fixed it. Is this a good solution? Should I add it as a hook somewhere, or is there a better way of automatically finding compilation databases?

Sarcasm commented 9 years ago

I was having the same problem, but then I found `irony-cdb-autosetup-compile-options', and that seems to have fixed it. Is this a good solution?

Depends on your problem. If your problem was that flycheck-irony didn't start and the default flycheck checker where used, then it is not the proper solution and you should do:

(require 'flycheck-irony)
(eval-after-load 'flycheck
  '(add-to-list 'flycheck-checkers 'irony))

If your issue is that the compile options weren't loaded automatically, then irony-cdb-autosetup-compile-options is recommended for that yes, as shown in the configuration section here: https://github.com/Sarcasm/irony-mode/blob/7211f8bf9daf692ba8d79f23e7ce61b3dba9965b/README.md#configuration

drvink commented 9 years ago

I somehow missed adding the irony-cdb-autosetup-compile-options line but had all the rest of them. Sorry to bother you--thanks!

typesanitizer commented 6 years ago

I ran into a similar issue today. What fixed the issue for me was that I was supplying the flag --std="c++11" (which works fine on the command line even though it doesn't seem to be documented anywhere), but once I set it to -std=c++11, flycheck-irony started working as expected.