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

std:: does not complete on Mac OS X #138

Open
sebastiansturm opened this issue Dec 7, 2014 · 27 comments
Open

std:: does not complete on Mac OS X #138

sebastiansturm opened this issue Dec 7, 2014 · 27 comments

Comments

@sebastiansturm
Copy link

Hi,

I have recently installed irony-mode on Mac OS X, with a homebrew-supplied libclang (from the 'llvm' package, currently at version 3.5). Unfortunately, the completion process doesn't pick up any standard library includes by default. For the following minimal example,

#include <string>
int main() {
  std::|
}

no completion candidates are offered. Running irony-server directly from the terminal shows that clang considers std an undeclared identifier. I can resolve the issue by explicitly passing the path to the stdlib header files to irony-server, i.e., by adding

   (list "-isystem" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1")

to the compile-options. Is there a better way to fix the stdlib completion issue? Since clang++ correctly picks up the header files during compilation (or flycheck syntax checking), I do not want to add the above include path to my compilation database.
best,
Sebastian

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

Hi,

Can you do a clean CMake build of irony-server to see what is printed in the log.
Particularly paying attention to the following:

  • libclang builtin headers directory
  • the presence of HAS_LIBCXX in the cmake generation output

Please post the complete cmake generation output, i.e:

$ cd /tmp
$ mkdir irony-server-build
$ cmake <path/to/irony-mode/server>
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
...

@sebastiansturm
Copy link
Author

Hi,

this is the complete cmake output:

cmake -DCMAKE_INSTALL_PREFIX\=/Users/sebastian/.emacs.d/irony/ /Users/sebastian/.emacs.d/elpa/irony-20141206.459/server && cmake --build . --use-stderr --config Release --target install
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Setting build type to 'Release' as none was specified
-- Performing Test HAS_STDCXX11
-- Performing Test HAS_STDCXX11 - Success
-- Performing Test HAS_CXX11_STDLIB
-- Performing Test HAS_CXX11_STDLIB - Success
-- C++11 compiler option(s): -std=c++11
-- Found LibClang: /usr/local/Cellar/llvm/3.5.0/lib/libclang.dylib  
-- Detecting libclang builtin headers directory
-- Detecting libclang builtin headers directory -- success
-- Irony package version is '0.2.0-cvs'
-- Found emacs: /Applications/emacs.app/Contents/MacOS/Emacs
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sebastian/.emacs.d/irony/build
Scanning dependencies of target irony-server
[ 16%] Building CXX object src/CMakeFiles/irony-server.dir/support/CommandLineParser.cpp.o
[ 33%] Building CXX object src/CMakeFiles/irony-server.dir/support/TemporaryFile.cpp.o
[ 50%] Building CXX object src/CMakeFiles/irony-server.dir/Command.cpp.o
[ 66%] Building CXX object src/CMakeFiles/irony-server.dir/Irony.cpp.o
[ 83%] Building CXX object src/CMakeFiles/irony-server.dir/TUManager.cpp.o
[100%] Building CXX object src/CMakeFiles/irony-server.dir/main.cpp.o
Linking CXX executable ../bin/irony-server
[100%] Built target irony-server
Install the project...
-- Install configuration: "Release"
-- Installing: /Users/sebastian/.emacs.d/irony/bin/irony-server

I have at least three different versions of clang installed in various locations (the Apple-supplied one, which is used as the default C/C++ compiler), the clang that comes with the Homebrew "llvm" package (currently at version 3.5) and the clang that comes with the Homebrew "llvm3.5" package (this one is also at v3.5.0, but in contrast to "llvm" includes libcxx support).

I guess it's just not a good idea to compile against the llvm package without libcxx support (?), but this is the package that is picked up by the default irony-server compilation commands.
best,
Sebastian

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

If you run ldd ~/.emacs.d/irony/bin/irony-server, what is the full path to libclang.dylib?

Is it /usr/local/Cellar/llvm/3.5.0/lib/libclang.dylib?

There is an homebrew issue with this package, see: Homebrew/legacy-homebrew#34169

That doesn't seem related though.

Do you know if you have another libclang.dylib on your system apart from the Homebrew ones?

By default irony should probably look for the one installed on the system, then in Homebrew.

@sebastiansturm
Copy link
Author

this is the output I get from otool -L:

irony-server:
    /usr/local/opt/llvm/lib/libclang.dylib (compatibility version 1.0.0, current version 0.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

All dylibs in /usr/local/opt/llvm/lib/ are symlinked to /usr/local/Cellar/llvm/3.5.0/lib/. There is a different homebrew issue that is probably relevant (Homebrew/legacy-homebrew#31754). The tl;dr is that the llvm maintainer has decided to add libcxx support only to explicitly versioned llvm packages (llvm34, llvm35, etc.)
Maybe that is even reasonable, as automatic updates to newer llvm versions might sometimes include backwards-incompatible changes to the completion API.
I could try out if std:: completion works with the llvm35-bundled libclang. Apparently Xcode also comes with a libclang, though I can't find libLLVM there. Would that be enough for autocompletion?
Sebastian

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

First a question about homebrew,
Would it be better if irony was looking at /usr/local/opt/ instead of /usr/local/Cellar?

It seems like the proper thing to do according to the following table
https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md#terminology---homebrew-speak but I'm not so familiar with Homebrew.

If you would be so kind as to test the change and see if it works, you can change the references to /usr/local/Cellar/ by /usr/local/opt/ and see if things still work, see

# LLVM Homebrew
"/usr/local/Cellar/llvm/${version}/include"

Another thing would be to swap the order of LLVM Homebrew and LLVM Homebrew/versions, so that versioned (~stable) packages will be looked up before unversionned one.

-    # LLVM Homebrew
-    "/usr/local/Cellar/llvm/${version}/include"
     # LLVM Homebrew/versions
     "/usr/local/lib/llvm-${version}/include"
+    # LLVM Homebrew
+    "/usr/local/opt/llvm/${version}/include"

I could try out if std:: completion works with the llvm35-bundled libclang. Apparently Xcode also comes with a libclang, though I can't find libLLVM there. Would that be enough for autocompletion?

I'm not sure to understand all this. Aren't you already using llvm35? Are you talking about the Homebrew versioned one? Why do you want libLLVM? Almost all libclang.dylib should be good to work with, except from a few gotchas for older versions, see FAQ.

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

The more I think about it the more I think that irony-mode shouldn't try to locate homebrew and it should be left to the user to do so, knowing he is using homebrew.

What does brew --prefix llvm<whatever> returns for your installation?

Does the Homebrew installation make the llvm-config<whatever> tool available?

@sebastiansturm
Copy link
Author

Hi,
I haven't yet tried out the changed cmake file, but I'll do soon.

Would it be better if irony was looking at /usr/local/opt/ instead of /usr/local/Cellar?

Unfortunately I'm far from a Homebrew expert myself, but I guess that defaulting to /usr/local/opt wouldn't change much because otool -L already returns a /usr/local/opt/... path.

I know my setup is a bit confusing. Right now I have two versions of LLVM 3.5, one is called simply llvm and picked up as the default llvm package by irony-server, the other is called llvm35 and is built with libcxx support (there is no such option for the llvm package). I guess there is no good reason to have both packages installed, so I might just get rid of llvm. On the other hand, installing llvm without any explicit version suffix seems like the natural thing to do, so I suspect there are other users running into the same issue.

I'm not sure to understand all this. Aren't you already using llvm35? Are you talking about the Homebrew versioned one? Why do you want libLLVM? Almost all libclang.dylib should be good to work with, except from a few gotchas for older versions, see FAQ.

I think I once had some rpath issues with irony-server that somehow involved libLLVM, so I thought that libLLVM was needed as well. If libLLVM is not needed, then maybe the standard cmake build could default to the libclang version that is bundled with Xcode. Most Mac-using programmers should have that installed anyway, so that seems to me like a safe choice and customized homebrew builds of irony-server could be left to expert users.

brew --prefix llvm returns /usr/local/opt/llvm, brew --prefix llvm35 returns /usr/local/opt/llvm35

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

I think I once had some rpath issues with irony-server that somehow involved libLLVM, so I thought that libLLVM was needed as well.

I think this is similar to this issue: Homebrew/legacy-homebrew#34169
Feel free to bump the issue so that the Homebrew guys know it's important.

know my setup is a bit confusing. Right now I have two versions of LLVM 3.5, one is called simply llvm and picked up as the default llvm package by irony-server, the other is called llvm35 and is built with libcxx support (there is no such option for the llvm package). I guess there is no good reason to have both packages installed, so I might just get rid of llvm.

I think, that irony-mode could at least check the versioned llvm before. If you can try it and see if that's enough for irony-server to work.

the standard cmake build could default to the libclang version that is bundled with Xcode

Sadly I think that the development files are not provided by XCode, only the runtime library is provided. I may be wrong though, I would be interested to know.

brew --prefix llvm returns /usr/local/opt/llvm, brew --prefix llvm35 returns /usr/local/opt/llvm35

Thank you,
what about llvm-config --prefix?

@sebastiansturm
Copy link
Author

Hm, changing the FindLibClang file produced the same results as before. If I add a path to the llvm35-bundled libclang, i.e.,

  list(APPEND libclang_llvm_header_search_paths
    # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
    "/usr/lib/llvm-${version}/include/"
    # Homebrew 3.5
    "/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/include"
...
  list(APPEND libclang_llvm_lib_search_paths
    # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/
    "/usr/lib/llvm-${version}/lib/"
    # Homebrew 3.5
    "/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/lib"

then the following error occurs:

cmake -DCMAKE_INSTALL_PREFIX\=/Users/sebastian/.emacs.d/irony/ /Users/sebastian/.emacs.d/elpa/irony-20141207.919/server && cmake --build . --use-stderr --config Release --target install
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Setting build type to 'Release' as none was specified
-- Performing Test HAS_STDCXX11
-- Performing Test HAS_STDCXX11 - Success
-- Performing Test HAS_CXX11_STDLIB
-- Performing Test HAS_CXX11_STDLIB - Success
-- C++11 compiler option(s): -std=c++11
-- Found LibClang: /usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/lib/libclang.dylib  
-- Detecting libclang builtin headers directory
-- Detecting libclang builtin headers directory -- fail
CMake Warning at cmake/CheckLibClangBuiltinHeadersDir.cmake:87 (message):
  CheckLibClangBuiltinHeadersDir: unsupported configuration, please report.



    Check with args: -isystem;"/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/lib/clang/3.5.0/include";/Users/sebastian/.emacs.d/irony/build/CMakeFiles/CMakeTmp/check-libclang-stddef.cpp
    Check output:
      dyld: Library not loaded: @rpath/libLLVM-3.5.dylib
    Referenced from: /usr/local/lib/llvm-3.5/lib/libclang.dylib
    Reason: image not found

I can link irony-server against the Xcode version of libclang if I add the following search paths:

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib"

However, I then have to explicitly add an rpath to irony-server (using install_name_tool) that points to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib. Also, I still have to supply an explicit include path pointing to the Xcode-bundled stdlib, otherwise there will be no std:: expansions.
Maybe there are some other configuration issues with my system. Are there any other Mac users reading this? Does std:: completion work for you?

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

Out of curiosity, can you try to do the following:

cmake -DCMAKE_PREFIX_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON 
make
./bin/irony-server --version

Is clang-c/Index.h available from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include?

For the rpath issue, see: https://github.com/Sarcasm/irony-mode/blob/4554edf926697782539ad601bf20756a5c02a1f2/README.md#faq

"/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/include"

Are you sure that this path contains the libclang API headers and not the clang compiler built-in header path?

irony-server at build time need the libclang API headers, called clang-c/Index.h.
irony-server at runtime needs the compiler built-in header directory path, this directory contains stddef.h for example.

@sebastiansturm
Copy link
Author

Hi,
the cmake flags you suggested produce the following build log,

-*- mode: compilation; default-directory: "~/.emacs.d/irony/build/" -*-
Compilation started at Sun Dec  7 20:45:35

cmake -DCMAKE_PREFIX_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON -DCMAKE_INSTALL_PREFIX\=/Users/sebastian/.emacs.d/irony/ /Users/sebastian/.emacs.d/elpa/irony-20141207.919/server && cmake --build . --use-stderr --config Release --target install
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Setting build type to 'Release' as none was specified
-- Performing Test HAS_STDCXX11
-- Performing Test HAS_STDCXX11 - Success
-- Performing Test HAS_CXX11_STDLIB
-- Performing Test HAS_CXX11_STDLIB - Success
-- C++11 compiler option(s): -std=c++11
-- Found LibClang: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib  
-- Detecting libclang builtin headers directory
-- Detecting libclang builtin headers directory -- success
-- Irony package version is '0.2.0-cvs'
-- Found emacs: /Applications/emacs.app/Contents/MacOS/Emacs
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sebastian/.emacs.d/irony/build
Scanning dependencies of target irony-server
[ 16%] Building CXX object src/CMakeFiles/irony-server.dir/support/CommandLineParser.cpp.o
[ 33%] Building CXX object src/CMakeFiles/irony-server.dir/support/TemporaryFile.cpp.o
[ 50%] Building CXX object src/CMakeFiles/irony-server.dir/Command.cpp.o
[ 66%] Building CXX object src/CMakeFiles/irony-server.dir/Irony.cpp.o
[ 83%] Building CXX object src/CMakeFiles/irony-server.dir/TUManager.cpp.o
[100%] Building CXX object src/CMakeFiles/irony-server.dir/main.cpp.o
Linking CXX executable ../bin/irony-server
[100%] Built target irony-server

Calling irony-server --version returns irony-server version 0.2.0-cvs. Happily, it does provide std:: autocompletion with the default compilation flags (no extra "-isystem" flag).

There are, however, no clang-c includes in the Xcode toolchain, so I guess this can't be used without Homebrew (or some other llvm installation) after all.

@sebastiansturm
Copy link
Author

I forgot to add, the path /usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5/include contains clang-c headers.

@sebastiansturm
Copy link
Author

on the other hand, the Xcode command line tools also include svn by default, and I have read that the libclang API is supposed to be stable. Would it be a reasonable option to get the clang-c includes from the clang svn repository, and use those to build irony-server?

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

Can you show the where irony found the libclang include?

Either using ccmake or cmake-gui or just by looking in the CMakeCache.txt file:

$ grep "^LIBCLANG_INCLUDE_DIR:" CMakeCache.txt
LIBCLANG_INCLUDE_DIR:PATH=/usr/include
$ grep "^LIBCLANG_LIBRARY:" CMakeCache.txt    
LIBCLANG_LIBRARY:FILEPATH=/usr/lib64/libclang.so

Would it be a reasonable option to get the clang-c includes from the clang svn repository, and use those to build irony-server?

So you mean, building with the clang-c/Index.h from svn but linking with the libclang.dylib from XCode? I do not recommend building with a more recent clang-c/Index.h than libclang.dylib. The opposite order should be fine on the other hand.

Irony-mode is checking CINDEX_VERSION_MAJOR and CINDEX_VERSION_MINOR to support version some functionality.

@sebastiansturm
Copy link
Author

It's using the include files supplied with llvm (not llvm35), and the Xcode version of libclang:

//The path to the directory that contains clang-c/Index.h
LIBCLANG_INCLUDE_DIR:PATH=/usr/local/Cellar/llvm/3.5.0/include
...
//The file that corresponds to the libclang library.
LIBCLANG_LIBRARY:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib

So you mean, building with the clang-c/Index.h from svn but linking with the libclang.dylib from XCode? I do not recommend building with a more recent clang-c/Index.h than libclang.dylib. The opposite order should be fine on the other hand.
Irony-mode is checking CINDEX_VERSION_MAJOR and CINDEX_VERSION_MINOR to support version some functionality.

If that could be used to download the right include files, that would be great. I don't know if the version numbers supplied by clang will actually correspond to llvm version numbers (Apple clang uses a versioning scheme of its own, as far as I can tell), but I guess that the few Apple-built clang versions that are released to the public could easily be hardcoded into the compilation script. Also, clang -v can be used to find out on which LLVM release a particular version of Apple clang is based (in the case of clang-600.0.56, it is "3.5svn")

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

If looks like your current setting with libclang.dylib coming and clang-c/Index.h coming from different sources is a bad idea.

Can you check if you have the llvm-config executable somewhere?

Can you try something else for me?

  1. Download clang+llvm-3.5.0-macosx-apple-darwin.tar.xz from http://llvm.org/releases/download.html
  2. Extract it somewhere (e.g: /tmp)
  3. make a clean build directory
  4. run cmake -DCMAKE_PREFIX_PATH=/tmp/clang+llvm-3.5.0-macosx-apple-darwin/ -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \</path/to/irony-mode/server/\>
  5. build and run make && ./bin/irony-server --version

Does that works?

I'm thinking about using this version more and more as I have a lot of issues with regard to Mac OS X and few people actually being fluent in either CMake or Homebrew.

@sebastiansturm
Copy link
Author

I do have llvm-config-3.5, bundled with the llvm35 package, and linked to /usr/local/bin. There is also llvm-config, included in the llvm path but hidden in what Homebrew calls the "Cellar". Xcode does not include llvm-config.
As far as I can tell, the alternative you suggested works like a charm, with std:: autocompletion and no need for rpath fixing. In my (relatively uninformed) opinion, it would be a good idea to download and use this version automatically unless the user provides a custom prefix_path.

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

That's good to know!

Did you use -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON? Because if you did that's probably the reason why you didn't have any issues regarding the rpath.

What does llvm-config-3.5 --prefix returns?

I think I will cleanup the CMake files:

  • Remove the Homebrew paths and use llvm-config instead, that could be useful on other platforms too!
  • Offer a way to automatically download and build with a release from http://llvm.org/releases/download.html

@sebastiansturm
Copy link
Author

Yes, I used -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON. This is what llvm-config-3.5 --prefix returns:

/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5

I think I will cleanup the CMake files:
Remove the Homebrew paths and use llvm-config instead, that could be useful on other platforms too!
Offer a way to automatically download and build with a release from http://llvm.org/releases/download.html

great, I'm looking forward to that!
thanks alot,
Sebastian

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 7, 2014

While we are at it, can you tell me what is the output of ls /usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5?

@sebastiansturm
Copy link
Author

sure, here you go:

total 0
11552692 drwxr-xr-x  44 sebastian  admin   1,5K 20 Nov 23:26 bin
11553534 drwxr-xr-x   3 sebastian  admin   102B 20 Nov 23:26 docs
11552052 drwxr-xr-x   9 sebastian  admin   306B  7 Dez 02:41 include
11552689 drwxr-xr-x  85 sebastian  admin   2,8K 20 Nov 23:26 lib
11543150 drwxr-xr-x   4 sebastian  admin   136B 20 Nov 23:10 libexec
11553549 drwxr-xr-x   4 sebastian  admin   136B 20 Nov 23:26 share
11553674 drwxr-xr-x   3 sebastian  admin   102B 20 Nov 23:27 usr

Just in case, this is the complete directory tree:

/usr/local/Cellar/llvm35/3.5.0/lib/llvm-3.5
├── bin
├── docs
│   └── llvm
│       ├── html
│       │   └── clang
│       └── ps
├── include
│   ├── c++
│   │   └── v1
│   │       ├── experimental
│   │       └── ext
│   ├── clang
│   │   ├── ARCMigrate
│   │   ├── AST
│   │   ├── ASTMatchers
│   │   │   └── Dynamic
│   │   ├── Analysis
│   │   │   ├── Analyses
│   │   │   ├── DomainSpecific
│   │   │   ├── FlowSensitive
│   │   │   └── Support
│   │   ├── Basic
│   │   ├── CodeGen
│   │   ├── Config
│   │   ├── Driver
│   │   ├── Edit
│   │   ├── Format
│   │   ├── Frontend
│   │   ├── FrontendTool
│   │   ├── Index
│   │   ├── Lex
│   │   ├── Parse
│   │   ├── Rewrite
│   │   │   ├── Core
│   │   │   └── Frontend
│   │   ├── Sema
│   │   ├── Serialization
│   │   ├── StaticAnalyzer
│   │   │   ├── Checkers
│   │   │   ├── Core
│   │   │   │   ├── BugReporter
│   │   │   │   └── PathSensitive
│   │   │   └── Frontend
│   │   └── Tooling
│   ├── clang-c
│   ├── llvm
│   │   ├── ADT
│   │   ├── Analysis
│   │   ├── AsmParser
│   │   ├── Bitcode
│   │   ├── CodeGen
│   │   │   └── PBQP
│   │   ├── Config
│   │   ├── DebugInfo
│   │   ├── ExecutionEngine
│   │   ├── IR
│   │   ├── IRReader
│   │   ├── LTO
│   │   ├── LineEditor
│   │   ├── Linker
│   │   ├── MC
│   │   │   ├── MCAnalysis
│   │   │   └── MCParser
│   │   ├── Object
│   │   ├── Option
│   │   ├── ProfileData
│   │   ├── Support
│   │   ├── TableGen
│   │   ├── Target
│   │   └── Transforms
│   │       ├── IPO
│   │       └── Utils
│   ├── llvm-c
│   │   └── Transforms
│   └── polly
│       ├── CodeGen
│       ├── Config
│       └── Support
├── lib
│   └── clang
│       └── 3.5.0
│           ├── include
│           │   └── sanitizer
│           └── lib
│               ├── darwin
│               └── macho_embedded
├── libexec
│   ├── cloog
│   │   ├── bin
│   │   ├── include
│   │   │   └── cloog
│   │   │       ├── isl
│   │   │       └── matrix
│   │   └── lib
│   │       ├── cloog-isl
│   │       ├── isl
│   │       └── pkgconfig
│   └── isl
│       ├── include
│       │   └── isl
│       │       └── deprecated
│       └── lib
│           └── pkgconfig
├── share
│   ├── llvm
│   │   └── cmake
│   └── man
│       └── man1
└── usr
    └── lib

@Sarcasm
Copy link
Owner

Sarcasm commented Dec 8, 2014

Great, thank you!

@tsukimizake
Copy link
Contributor

Pardon me for jumping in.

Since clang++ correctly picks up the header files during compilation

Is it exactly the clang++ from homebrew llvm, not the default installed one or versions/llvm35's?
Does /usr/local/Cellar/llvm/3.5.0/bin/clang++ work fine?

@tsukimizake
Copy link
Contributor

Oh,my. It seems to be solved already. Sorry for disturbing...

@deniskokarev
Copy link

There is a good chance that you may don't even need brew (if you already have cmake).

irony-server compiles and works on OSX Yosemite with standard libclang from Xcode7. The only piece missing is clang-c header files, which may be borrowed from llvm 3.8 ;-)

Quick and dirty way to build irony-server on Yosemite with Xcode7

### create /usr/local if not there yet
sudo mkdir -p /usr/local/lib /usr/local/include
### grab standard libclang
sudo cp -p "`xcode-select --print-path`"/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /usr/local/lib
### (dirty part) supplement with latest llvm clang-c includes
cd /tmp
svn export http://llvm.org/svn/llvm-project/cfe/trunk/include/clang-c/
sudo cp -RP clang-c /usr/local/include

M-x irony-install-server should give you no trouble after that. Compiles and works.

One more step required on OSX - need to find where Xcode keeps all header files to add them to your .clang_complete. Otherwise irony is useless.

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
...

Adding to irony-additional-clang-options should work as well

@voldyman
Copy link

voldyman commented Mar 23, 2016

I again stumbled on this issue, my setup is clang using homebrew then built the irony server and ran emacs, but wasn't getting any coherent results which is certainly not the case on Ubuntu/elementary OS.
The problem was that irony-server wasn't able to find the default/system headerfiles and hence std namespace was undefined.

the fix for me was adding this to my use-package's :config

   (custom-set-variables
   '(irony-additional-clang-options
     '("-I/Library/Developer/CommandLineTools/usr/include/c++/v1")))

Hope it helps someone.

@fuzunspm
Copy link

I again stumbled on this issue, my setup is clang using homebrew then built the irony server and ran emacs, but wasn't getting any incoherent which is certainly not the case on Ubuntu/elementary OS.
The problem was that irony-server wasn't able to find the default/system headerfiles and hence std namespace was undefined.

the fix for me was adding this to my use-package's :config

   (custom-set-variables
   '(irony-additional-clang-options
     '("-I/Library/Developer/CommandLineTools/usr/include/c++/v1")))

Hope it helps someone.

After hours of trial and errors, you just made my day

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

6 participants