Install LLVM in MacOS - c++

I am learning LLVMand C++, but I find it hard to import LLVM into my project.
The first problem is my system has already installed clang and clang++ in usr/bin, but the other LLVM which was installed by brew is in /opt/homebrew/opt/llvm, is ok to delete clang in usr/bin and add opt/homebrew/opt/llvm/bin to env variable?
The second problem is how to link LLVM to my VSCode project, I try link LLVM by
#include "/opt/homebrew/opt/llvm/include/llvm/IR/Constants.h"
but it can't work.
Thanks for any help !!!

Never delete system utilities. Of any kind. For any reason.
Read the information presented to you in brew info llvm. This information was shown to you when you installed it.
Don't #include absolute paths.
Learn how to use compiler/linker flags to tell your compiler where to find headers/libraries.
Read the libc++ documentation to learn how to specify a specific libc++.
Finally, use a tool like cmake to automate this for you.
A homespun makefile might be sufficient.
What you are attempting to do is highly non-trivial. As one of the comments suggests, I would also recommend getting familiar with what's baked in before you try switching to a custom version.

Related

How to use clangd to find headers of gcc on MacOS

My system is macOS 12.3 21E230 arm64 and I have installed gcc and llvm from homebrew.
I use Neovim as editor and use nvim-lsp via clangd to complete my code, and it works well with clang.
Now I want to use clangd to find headers of gcc and compelete them in my code. I have tried to find answer from https://clangd.llvm.org/, but I haven't find any way to solve this problem.
I tried setting --query-driver, -include-dir, -isysroot, etc.
Using --query-driver seems to be the most promising approach.
If it's not working, please share more details in the form of clangd logs.
Some clangd issues reported my Mac users that might contain helpful discussion are:
https://github.com/clangd/clangd/issues/487
https://github.com/clangd/clangd/issues/1079

clangd on linux cannot find default headers

I've installed the newest LLVM toolchain from the official PPA, including clang, clang-tools-extra, lldb, lld, libc++ and libc++abi. I'm trying to use clangd with emacs + lsp.
All works fine except clangd cannot find default headers like memory, vector and so on. My code is fine, it is normally compiled using clang. My compile_commands.json also okay.
How to make clangd work?
Edit: removed mention about building llvm+clang from sources since it has been done incorrectly.
I didn't find any info on the internet, so posting the solution here.
Suppose the llvm toolchain is installed in /usr/lib/llvm-8.
The answer is:
sudo ln -s /usr/lib/llvm-8/include/c++/v1 /usr/include/c++/v1
That's it. Good luck.

How to get Xapian working with MSVC?

I would like to use Xapian search engine with a Qt application I am developing. The compiler used is MSVC (Visual Studio 2013). As it turns out, the Xapian download page (https://xapian.org/download) which was supposed to hold the link to a set of makefiles for MSVC, are missing.
I thought maybe instead of trying too hard to get it working under MSVC, let's get MinGW + MSYS environment to build and run this guy. However, there I ran into a problem. It required zlib library.
configure: error: zlib.h not found - required for chert and glass (you may need to install zlib1g-dev or zlib-devel package)
Building zlib doesn't seem too easy, as instead of running the "configure" script right away, it suggested me to check Makefile.gcc within /win32 folder. This however wasn't the answer, it didnt really seem to do much.
$./configure
Checking for gcc…
Please use win32/Makefile.gcc instead.
I am probably doing it wrong or perhaps have hit a circle somewhere. Some help would be really appreciated. Looking forward to some insight.
My main concern is to get Xapian working on Windows.

How to build and install GCC on Windows 7, ver. 4.8.1

I would like to upgrade my old GCC compiler to v. 4.8.1.
Currently I'm using Code::Blocks IDE (nightly build, svn 8982), and my compiler is GCC 4.4.1.
I downloaded fresh GCC from their site - gcc.gnu.org
From what I've read in documentation, they say that I should first build compiler by myself. Afterwards, they throw something like this:
% mkdir objdir
% cd objdir
% srcdir/configure [options] [target]
However, I completly have no idea what to do with these lines.
And even if I did, afterwards come maaany lines with some additional options, where I am even more lost then before.
I don't know if there is any easy way of installing it, but from what I've read here, I can download MSYS from MinGW and it will do everything(I hope?) for me. However, from what I see there, it says that MinGW comes with already built version of GCC, meaning I won't be able to use mine anyway. Am I right? If yes, what should I do to build and use GCC? If not, then will I be able to easily install GCC after downloading MSYS?
Thanks in advance.
I can download MSYS from MinGW
YOu can.
and it will do everything(I hope?) for me.
It won't. MSys provides environment for building software that requires unix-like environment. To be more precise - autotools. If you aren't familiar with *nix build process (configure script), Mingw won't really help you.
However, from what I see there, it says that MinGW comes with already built version of GCC,
Yes, version 4.7.2 at the moment.
meaning I won't be able to use mine anyway. Am I right?
No. If you don't add Mingw/MSys to your PATH, you can keep multiple different installations on the same machine. It also SHOULD be possible to use multiple different versions of gcc within the same installation of mingw, but things can get messy here. (gcc3 and gcc4 should be able to exist, not sure about 4.7.2 and 4.8.1)
If yes, what should I do to build and use GCC?
You should search for precompiled binaries provided by somebody else. Compiling gcc yourself is possible, but for you (i.e. if you aren't arleady familiar with msys) it might not be worth the effort.
Either you could try http://mingw-w64.sourceforge.net/ or mingw-nuwen. Mingw provided by nuwen is 32bit only, but is very easy to install. The problem is that standard mingw distribution includes update tool (with "mingw uppdate" and "mingw upgrade" you can upgrade installed packages to their latest version), bug "mingw-nuwen" doesn't have such tool.
Because you say
However, I completly have no idea what to do with these lines.
You should either use precompiled mingw provded by somebody else, or use another compiler. If you don't really need bleeding-edge C++11 support ON WINDOWS, use visual studio express.

Which compiler did macport use?

I'm working on a c++ project which just implemented some of the shared pointer features from boost and/or TR1. Since the upgrade, my code no longer compiles with gcc 4.2.1 (provided by Xcode), I'm installing gcc 4.5.x which is suppose to provide the aforementioned features. I need to recompile mpich2 (and then my code) with the new compiler and I want to be sure macport is using the right one.
sudo port install gcc45
gcc_select mp-gcc45
should have gotten the job done, but I'd like port to tell me which compiler it is using.
Can anyone help me with this?
Thanks in advance,
Nick
MacPorts - Using the Right Compiler