Skip to content

Instantly share code, notes, and snippets.

@dlentini
Last active April 10, 2021 06:46
Show Gist options
  • Save dlentini/ae47a2f89cc9b86987a8 to your computer and use it in GitHub Desktop.
Save dlentini/ae47a2f89cc9b86987a8 to your computer and use it in GitHub Desktop.
Installation steps for SublimeClang on OS X

How to get SublimeClang, https://github.com/quarnster/SublimeClang, going on OS X

First step clone SublimeClang repo into your Sublime package directory.

# git clone https://github.com/quarnster/SublimeClang.git
# cd SublimeClang
# git pull && git submodule foreach --recursive git pull origin master

Next step is to compile libcache.dylib from SublimeClang/src. There is a cmake project for doing this but I never got it to work and as it seems to be only one file, it is farly easy to figure this out. And don't get fooled this is not the same as the libcache.dylib that is available in the system.

# cd src
# clang++ -dynamiclib -I. -DSUBLIMECLANG_VERSION=\"1.0.41\" -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ -lclang -std=c++11 main.cpp -o libcache.dylib
# cp libcache.dylib ..

Next is to fixup the SublimeClang config. The default is for an ancient version of toolchain so it needs to be changed. If you are on a different version then I am, you get all the paths by compiling a file with -v like clang++ -v yourfile.cpp.

diff --git a/SublimeClang.sublime-settings b/SublimeClang.sublime-settings
index 1b510f3..26c71db 100644
--- a/SublimeClang.sublime-settings
+++ b/SublimeClang.sublime-settings
@@ -148,3 +148,3 @@
         // For example, you can use "c++": ["-std=c++11"] to enable C++11 features.
-        "c++" : [],
+        "c++" : ["-std=c++11"],
         "c": [],
@@ -272,5 +272,8 @@
     [
-        "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/",
-        "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/4.2.1",
-        "-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/",
+        "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk",
+        "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
+        "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include",
+        "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
+        "-isystem", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include",
+        "-F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/",
         "-Wno-deprecated-declarations",
@@ -304,3 +307,3 @@
     // included headers
-    "dont_prepend_clang_includes": false,
+    "dont_prepend_clang_includes": true,
 
@zizhengwu
Copy link

Thank you so much for sharing how to compile libcache.dylib. It works for me. However, there should be one more step of copying libclang.dylib.

BTW, the following config works for me on OS X 10.11

"options":
[
  "-isystem", "/Library/Developer/CommandLineTools/usr/lib/clang/7.0.2/include/",
  "-isystem", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/",
  "-I", "/usr/local/include/",
  "-Wall"
]

However, it seems that SublimeClang can't provide completion for unique_ptr. Could you give it a try?

screen shot 2016-01-02 at 6 30 21 pm

@rdlaner
Copy link

rdlaner commented Sep 24, 2016

I can't seem to get it working with Sublime Text 3.
I was able to successfully build libcache.dylib and copied it into ...Packages/SublimeClang/
I also took libclang.dylib from the SublimeClang-1.0.41 package I downloaded from the SublimeClang github repo and placed it in the same directory with libcache.dylib.

However, I still can't get SublimeClang to work; none of the hot-keys do anything.

Did place libcache and libclang in the correct directory? Some other guides suggests placing them in the internals directory, even though that did not work for me.
Should I get libclang.dylib from somewhere else?
What else could I be missing?

Thanks for your help!

@rdlaner
Copy link

rdlaner commented Sep 25, 2016

Ok, so I figured out what I needed in case it helps anyone else.

Instead of using libclang.dylib from the SublimeClang-1.0.41 package downloaded from the SublimeClang github repo, I copied it from my current version of clang on my machine, which is at this path:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib.

After I rebuilt libcache.dylib, everything worked fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment