Sarcasm / irony-mode

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

Irony-flycheck ignores compilation flags #177

Closed jeremysalwen closed 9 years ago

jeremysalwen commented 9 years ago

I seem to be having a similar problem as issue #171 , except when I run the same diagnostics, I don't have the same issue with linking to different versions of libLLVM. I am running the latest version from MELPA.

Here are the results of all the same diagnostics tests:

directory structure is

/home/jeremy/project/
---.clang_complete
---src/
------Optimizable.cpp
---include/
------Optimizable.hpp

I open Optimizable.cpp

irony-cdb-menu:

Working directory: /home/jeremy/project
Compile options: -std=c++11 -Iinclude

irony--adjust-complie-options:

("-x" "c++" "-working-directory" "/home/jeremy/deeplearning/HessianFree/" "-std=c++11 -Iinclude")

$ ~/.emacs.d/irony/bin/irony-server diagnostics /home/jeremy/deeplearning/HessianFree/src/Optimizable.cpp

error: invalid number of arguments for 'diagnostics' (requires 0 got 1)

$ ldd ~/.emacs.d/irony/bin/irony-server

    linux-vdso.so.1 (0x00007fffa80b0000)
    libclang-3.5.so.1 => /usr/lib/x86_64-linux-gnu/libclang-3.5.so.1 (0x00007f4c56240000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4c55f30000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4c55c28000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4c55a10000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4c55660000)
    libLLVM-3.5.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-3.5.so.1 (0x00007f4c53938000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4c53718000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4c534f8000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f4c532f0000)
    libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f4c530b0000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f4c52e80000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4c52c78000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f4c56e90000)
    libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f4c52a68000)

$ ldd /usr/bin/clang++

    linux-vdso.so.1 (0x00007fffc9658000)
    libLLVM-3.5.so.1 => /usr/lib/x86_64-linux-gnu/libLLVM-3.5.so.1 (0x00007f3eaa670000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f3eaa450000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3eaa230000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f3eaa028000)
    libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f3ea9de8000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f3ea9bb8000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3ea99b0000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3ea96a0000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3ea9398000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3ea9180000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3ea8dd0000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3eac3c0000)
    libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f3ea8bc0000)

irony-flycheck still gives warnings such as

      in-class initialization of non-static data member is a C++11 extension... (irony)

and errors such as

        'Optimizable.hpp' file not found... (irony)
Sarcasm commented 9 years ago

$ ~/.emacs.d/irony/bin/irony-server diagnostics /home/jeremy/deeplearning/HessianFree/src/Optimizable.cpp

Getting the diagnostics is a 2-step operation (it's recent), you have to do this:

~/.emacs.d/irony/bin/irony-server -i
parse /home/jeremy/deeplearning/HessianFree/src/Optimizable.cpp
-x c++ -working-directory /home/jeremy/deeplearning/HessianFree/ -std=c++11 -Iinclude
t
diagnostics
<diagnostics...>

What is the output for the diagnostics?

jeremysalwen commented 9 years ago
jeremy@jeremy-laptop:~$ ~/.emacs.d/irony/bin/irony-server -i
parse /home/jeremy/deeplearning/HessianFree/src/Optimizable.cpp
-x c++ -working-directory /home/jeremy/deeplearning/HessianFree/ -std=c++11 -Iinclude
execute: Command{action=Command::Parse, file='/home/jeremy/deeplearning/HessianFree/src/Optimizable.cpp', line=0, column=0, flags=['-x', 'c++', '-working-directory', '/home/jeremy/deeplearning/HessianFree/', '-std=c++11', '-Iinclude'], unsavedFiles.count=0, opt=off}
t

;;EOT
diagnostics
execute: Command{action=Command::Diagnostics, file='', line=0, column=0, flags=[], unsavedFiles.count=0, opt=off}
(
)
Sarcasm commented 9 years ago

That looks about fine.

Can you check the irony-server log file in /tmp/?

And see what is the parse command flags?

execute: Command{action=Command::Parse, file..., flags=[???], ...}

You can edit the irony-server command to add more logging by adding "-d" after "-i", here: https://github.com/Sarcasm/irony-mode/blob/1241a6941628224bed7936605c3c1bb44869cf19/irony.el#L566

jeremysalwen commented 9 years ago

The contents of /tmp/irony*.log are

execute: Command{action=Command::Parse, file='/home/jeremy/deeplearning/HessianFree/test/testmnist.cpp', line=0, column=0, flags=['-x', 'c++', '-working-directory', '/home/jeremy/deeplearning/HessianFree/', '-std=c++11 -Iinclude'], unsavedFiles.count=1, opt=off}
execute: Command{action=Command::Diagnostics, file='', line=0, column=0, flags=[], unsavedFiles.count=0, opt=off}
Sarcasm commented 9 years ago

Okay, I'm a bit clueless as it is.

Does this happen only with this file or any other file? Would you be able to provide me with a reduced test-case?

What is your platform? OS, Emacs version, irony and flycheck-irony version, ...

jeremysalwen commented 9 years ago

It is only with this project, a previous project worked fine.

I am running latest debian unstable, emacs 24.4.1, with packages irony, irony-company, irony-flycheck, company, flycheck, yasnippet, magit.

All packages are installed from MELPA and are up to date.

This is my entire .emacs

(require 'package) ;; You might already have this line
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line

(require 'comint)
(setq comint-prompt-read-only t)
(setq comint-scroll-to-bottom-on-input t)

(load-library "yasnippet")
(require 'yasnippet)
(yas-global-mode 1)

(load-library "magit")
(require 'magit)

(load-library "irony")
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)

(load-library "company")
(add-hook 'after-init-hook 'global-company-mode)

(load-library "company-irony")
(eval-after-load 'company
  '(add-to-list 'company-backends 'company-irony))

;; (optional) adds CC special commands to `company-begin-commands' in order to
;; trigger completion at interesting places, such as after scope operator
;;     std::|
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)

(load-library "flycheck")
(add-hook 'after-init-hook #'global-flycheck-mode)

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

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(company-idle-delay 0.2)
 '(company-minimum-prefix-length 2)
 )

(require 'server)
(server-start)

(setq redisplay-dont-pause t
  scroll-margin 1
  scroll-step 1
  scroll-conservatively 10000
  scroll-preserve-screen-position 1)

(provide '.emacs)
;;; .emacs ends here

The project I am using is available on github: https://github.com/jeremysalwen/HessianFreePP. None of the files that require c++11 or includes have proper syntax checking, but in particular test/testmnist.cpp is the one I care about.

Sarcasm commented 9 years ago

Hi,

I'm sorry but testing is a bit difficult for me due to the few libraries that are involved.

It looks like Optimizable.hpp is lacking a header guard. It also doesn't include the <armadillo> explicitly.

The format for .clang_complete is one flag per line. In your case you have multiple flags and I cannot guarantee that it will work.

If you are able to reproduce the issue without external libraries that would be helpful so I can test as well.

jeremysalwen commented 9 years ago

Hi, thank you very much! The problem was that .clang_complete requires one flag per line. When I fixed that, it worked perfectly. Is there a reason why it is necessary to have one flag per line?

On Sun, Mar 1, 2015 at 2:31 PM, Guillaume Papin notifications@github.com wrote:

Hi,

I'm sorry but testing is a bit difficult for me due to the few libraries that are involved.

It looks like Optimizable.hpp is lacking a header guard. It also doesn't include the explicitly.

The format for .clang_complete is one flag per line. In your case you have multiple flags and I cannot guarantee that it will work.

If you are able to reproduce the issue without external libraries that would be helpful so I can test as well.

— Reply to this email directly or view it on GitHub https://github.com/Sarcasm/irony-mode/issues/177#issuecomment-76625715.

Sarcasm commented 9 years ago

That's the way Rip-Rip/clang_complete works, I wanted the .clang_complete to work with it: https://github.com/Rip-Rip/clang_complete/blob/1724008e987de584bec0823bfb8959b0a3183c51/doc/clang_complete.txt#L56

It allows to work with compile definition that contains space (in path or defines that may happen), e.g:

-DFOO="foo bar baz"
-Iblah/blih  blouh/