Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find header files #546

Open
iwahbe opened this issue Aug 18, 2019 · 2 comments
Open

Cannot find header files #546

iwahbe opened this issue Aug 18, 2019 · 2 comments

Comments

@iwahbe
Copy link

iwahbe commented Aug 18, 2019

When I have a .c file open, emacs cannot auto-complete on standard library .h files, and functions from standard library .h files show up as errors. On my #includes I get 'string.h' file not found'. However, I can use cmake to build what I write with standard libraries. Please help.
This the relevant part of my init file:

(use-package irony
  :ensure irony
  :hook ((c-mode objc-mode c++-mode) . irony-mode)
  :config
  (irony-cdb-autosetup-compile-options)
  (use-package clang-format
    :ensure t
    :config
    (setenv "Clang_DIR" "/usr/local/Cellar/llvm/8.0.1/Toolchains/LLVM8.0.1.xctoolchain/usr/lib/cmake/clang/")
    (setq clang-format-executable "/usr/local/opt/llvm/Toolchains/LLVM8.0.1.xctoolchain/usr/bin/clang-format")
    (add-hook 'before-save-hook (lambda ()
				  (when (eql major-mode 'c-mode)
				    (clang-format-buffer))
				  )
	      )
    )
  (use-package irony-eldoc
    :ensure t
    :config
    (irony-eldoc +1)
    )
  (use-package flycheck-irony
    :ensure t
    :after (flycheck)
    :config
    (add-hook 'flycheck-mode-hook #'flycheck-irony-setup)
    (flycheck-irony-setup)
    (flycheck-mode +1)
    )
  (use-package company-irony
    :after (company irony)
    :ensure t
    :config
    (add-to-list 'company-backends 'company-irony)
    )
  (defun c-compile-buffer ()
    (interactive)
    (let ((in buffer-file-name) (out (file-name-sans-extension buffer-file-name)))
      (compile (concat "cc '" in "' -o '" out "'"))))
  (local-set-key (kbd "C-c C-c") #'c-compile-buffer)
  (my-prog-mode)
  (message "%s" "c/objc/c++ has been set up ")
  )

When I reinstall the irony server, this is the message I get:

-*- mode: compilation; default-directory: "/var/folders/0r/dc8810mn34jcnfh16vgw3_d80000gn/T/build-irony-server-1.3.1/" -*-
Compilation started at Sat Aug 17 19:32:22

cmake -DCMAKE_INSTALL_PREFIX\=/Users/ianwahbe/.emacs.d/irony/  /Users/ianwahbe/.emacs.d/elpa/irony-20190703.1732/server && cmake --build . --use-stderr --config Release --target install
-- Irony package version is '1.3.1'
-- Found emacs: /Applications/emacs.app/Contents/MacOS/Emacs
-- Configuring done
-- Generating done
-- Build files have been written to: /private/var/folders/0r/dc8810mn34jcnfh16vgw3_d80000gn/T/build-irony-server-1.3.1
[100%] Built target irony-server
Install the project...
-- Install configuration: ""
-- Installing: /Users/ianwahbe/.emacs.d/irony/bin/irony-server

Compilation finished at Sat Aug 17 19:32:22
@alutwak
Copy link

alutwak commented Oct 2, 2019

I'm also running into the same issue after doing an irony upgrade (to irony-20190703.1732) at roughly the same time that I did an OS upgrade (to OSx 10.14), which also included an Xcode upgrade.

irony is working just fine, except that it's not finding any of the headers from either the c or c++ standard library.

I've tried building irony with the four llvm builds on my system, which include the native Xcode (prefix path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/), and three different versions from MacPorts: llvm-8.0, llvm-7.0, and llvm-6.0 (which is what I think I was using before).

The irony-server seems to be building just fine:

-*- mode: compilation; default-directory: "/var/folders/2y/hqhdgbyj6vnf40gnhzlpjn540000gn/T/build-irony-server-1.3.1/" -*-
Compilation started at Wed Oct  2 15:05:21

cmake -DCMAKE_PREFIX_PATH=/opt/local/libexec/llvm-8.0/ -DCMAKE_CXX_COMPILER=/opt/local/libexec/llvm-8.0/bin/clang++ -DCMAKE_C_COMPILER=/opt/local/libexec/llvm-8.0/bin/clang -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON -DCMAKE_INSTALL_PREFIX\=/Users/worm/.emacs.d/irony/  /Users/worm/.emacs.d/elpa/irony-20190703.1732/server && cmake --build . --use-stderr --config Release --target install
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- Check for working C compiler: /opt/local/libexec/llvm-8.0/bin/clang
-- Check for working C compiler: /opt/local/libexec/llvm-8.0/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/local/libexec/llvm-8.0/bin/clang++
-- Check for working CXX compiler: /opt/local/libexec/llvm-8.0/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Irony package version is '1.3.1'
-- Found emacs: /usr/local/bin/emacs
-- Configuring done
-- Generating done
-- Build files have been written to: /var/folders/2y/hqhdgbyj6vnf40gnhzlpjn540000gn/T/build-irony-server-1.3.1
Scanning dependencies of target irony-server
[ 12%] Building CXX object src/CMakeFiles/irony-server.dir/support/CommandLineParser.cpp.o
[ 25%] Building CXX object src/CMakeFiles/irony-server.dir/support/TemporaryFile.cpp.o
[ 37%] Building CXX object src/CMakeFiles/irony-server.dir/Command.cpp.o
[ 50%] Building CXX object src/CMakeFiles/irony-server.dir/CompDBCache.cpp.o
[ 62%] Building CXX object src/CMakeFiles/irony-server.dir/Irony.cpp.o
[ 75%] Building CXX object src/CMakeFiles/irony-server.dir/TUManager.cpp.o
[ 87%] Building CXX object src/CMakeFiles/irony-server.dir/main.cpp.o
[100%] Linking CXX executable ../bin/irony-server
[100%] Built target irony-server
Install the project...
-- Install configuration: ""
-- Installing: /Users/worm/.emacs.d/irony/bin/irony-server

Interestingly, when I use llvm-7.0 or llvm-8.0, flycheck-irony can't find the header files themselves, but it's not complaining about the functions that should be in those headers and company-irony is suggesting them for me (i.e. #include gives an error, but memset() works just fine).

However, when I use llvm-6.0 or Xcode, flycheck doesn't complain on the header files and instead complains on the functions (for instance, memset and memcpy both result in "undeclared identifier" errors).

I've played around with manually setting the LIBCLANG_LIBRARY and LIBCLANG_INCLUDE_DIR options, and I've used install_name_tool to force irony-server to point to the correct libclang.dylib, but I'm still seeing the same issues.

I've been through many battles over the years with reconfiguring irony after llvm updates, but this one finally has me stumped.

@alutwak
Copy link

alutwak commented Oct 4, 2019

Ok, I bit the bullet and added my system include paths to a .clang_complete file (as per the Mac OS X issues and workaround wiki entry) and now it seems like everything's working again. So I was probably just taking up extra bandwidth by adding to this thread, since it seems like that's pretty much the go-to fix for header issues on a Mac.

But I'm still curious about why irony doesn't automatically know where the system headers are. I'm assuming that these would be built into the libclang library, and they're clearly available to clang, since I can compile with it without adding extra -I's.

As an aside, and perhaps a path to a possible solution: xcode has a command called "xcrun" to set up a build environment for you. In fact, all of the clang commands that MacPorts installs are just scripts that run "xcrun /path/to/executable/clang-tool." If I try to run those executables on their own without xcrun then I get the same errors that irony throws. Unfortunately, running irony-server with xcrun doesn't make any difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants