Where is the system llvm-config on macOS? - xcode

If I'm not mistaken, the compiler etc. installed as part of XCode use llvm. But I can't find an llvm-config binary to generate proper flags for command-line compilation to an llvm target. Where is such a thing on macOS?
I know I can install a new llvm via MacPorts or Homebrew, but I don't want to duplicate what's already there; I just want a way to get at the system configuration.

llvm-config is used to build programs that would link against LLVM.
Xcode does not distribute the LLVM libraries, and does not support linking against clang itself, so llvm-config is of no use in this context. What is your use case?

Related

Interdependences of homebrew llvm, gcc and XCode

So far, I have understood that on a MacOS system, on which I have installed XCode and nothing from Homebrew, clang++ comes from XCode, and g++ is an alias for XCode's clang++. Now, when I install Homebrew's llvm oder gcc, there seems to be some dependency on the stuff provided by XCode.
Specifically, I'd like to know:
which headers and libraries are used if I use Homebrew's llvm/gcc?
in particular, which are the standard libraries used? I somewhere read that XCode's llvm doesn't use libc++ anymore.
how can I control that?
what parts from XCode are used?
which compatibility issues do I have to face?
is there a Homebrew-only build toolchain I can use?
I am sorry for this question, but after several build errors occurring with one compiler but not the other, I am a bit lost in how my system works. So far, I have installed XCode and Homebrew's llvm, and try compiling my program with either of them, with different outcome.

Using cmake on macOS force building shared libraries in .so version instead of .dylib

I have a problem with forcing building shared libraries on macOS in typical .so standard way for GNU GCC compiler. I force to use GCC instead of Clang compiler, but CMake still produce .dylib instead of .so. Can anybody tell me, how can I force to create so instead of dylib, because my lib need to have .so version?
did you try CMAKE_SHARED_LIBRARY_SUFFIX ?
ref: https://cmake.org/cmake/help/latest/variable/CMAKE_SHARED_LIBRARY_SUFFIX.html

Using gcc instead of clang in ghci or ghc

On Mac OSX 10.9, the default c compiler bundled with Xcode is clang. I installed gcc-4.9 with homebrew. Now I have two different gccs, one is clang, the other is gcc. The default is clang.
I want to use gcc when compiling Haskell files with ghc, and I want also gcc when I launch ghci. How to do this change?
Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371
Type ghc --print-libdir
The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3
Go to that directory and edit the settings file.
There'll be a line indicating the path to the C compiler. It'll probably say /bin/gcc
Change that line to /usr/local/bin/gcc-4.8 (or whichever gcc version you brew installed, such as /usr/local/bin/gcc-4.2)

Proper way to upgrade from llvm-g++-4.2 to g++-4.7 on Mac

I have Lion 10.7.3 with the Command-line tool installed. I wanted to experiment with C++11, so I used homebrew to install GCC 4.7 as documented here.
How can I now upgrade the /usr/bin/g++ to be the one installed by Homebrew? Is it as simple as symlinking it? I just want to double check and make sure. Thanks!
First, are you sure you need g++ 4.7? As you can see from the C++11 implementation status page, recent versions of clang support most of C++11 too. Of course there are still things that g++ handles and clang doesn't, but there are also still things that clang supports and g++ doesn't. And, more importantly, you already have a recent version of clang, from Apple, configured and ready to go, as your default compiler. Plus, g++ after 4.2 doesn't support Mac extensions like, say, -arch, which means you can't use it to build a whole lot of third-party software (because most configure scripts assume that if you're on a Mac, your compiler supports Mac extensions).
But if you want g++ 4.7, you can do it. Just not by trying to replace /usr/bin/g++ with a different version. Never replace anything in /usr/bin (or /System) with non-Apple stuff except in a few very rare cases (when you have a strong reassurance from someone who knows what they're talking about).
A better thing to do is to just install another compiler in parallel. Just let Homebrew install its favorite way (so it installs into some prefix like /usr/local/Cellar/gcc/4.7, then symlinks all the appropriate stuff into /usr/local/bin, etc.), and use it that way.
When compiling your code, instead of writing g++, write /usr/local/bin/g++, or g++-4.7.
If you get tired of doing that, put /usr/local/bin higher on your PATH that /usr/bin, or create a shell alias, or stick it in the environment variable CXX and write $CXX instead of g++.
If you're using a GUI IDE, you should be able to configure it to use your compiler by setting the path to it somewhere. (Unless you're using Xcode, which you can only configure to work with Apple-tested compilers.)
This is all you need for experimenting with your own code. If you want to compile third-party applications with this compiler, that may be a bit more complicated. You don't often actually compile each source file and link the result together; you just do configure && make and let them do the heavy lifting for you.
Fortunately, most packages will respect the standard environment variables, especially CXX for specifying a default C++ compiler and CC for a default C compiler. (That's why I suggested the name CXX above.)
Just remember that, again, g++ 4.7 doesn't support Mac extensions, so if you're not prepared to debug a bunch of autoconf-based configure scripts complaining that your compiler can't generate code because it assumed it could throw -arch x86_64 at any compiler on a Mac, etc., don't do this.

Obtaining GCC for OSX with Developer Tools installed

I want to start working with C++0x. I see that GCC 4.7 has a fair amount of functionality available. I already have XCode 3.2 installed in /Developer
I downloaded: http://fileboar.com/gcc/snapshots/LATEST-4.7/gcc-4.7-20110528.tar.bz2
Can I somehow compile this in /opt/gcc-4.7? How do I then work with my path so I can compile with GCC 4.7 from the command-line but have OSX use the version it needs?
OSX does not need gcc to run - the Developer tools are optional. So you only need to choose between gcc's when you compile. In Xcode you chose explicitly the gcc andin Makefiles you can set $(CC) or similar to the full path.
Alternatively rename the gcc-4.7 gcc to gcc-4.7 and use that so gcc is always the Apple one.
For ease of using multiple C++ compilers I use macports (or fink or homebrew) which will compile the compilers with the correct patches and also has a port select command to switch between the C++ compilers

Resources