Is it possible to build boost with clang and gcc s

2019-08-14 20:30发布

问题:

I am running into an odd problem, where I need to access boost libraries using both gcc and clang specific modules (these programs interact. One is gcc/g++ exclusive, and one is clang exclusive). Is there any way to build boost so that both modules access the same location when calling boost, but boost is able to facilitate gcc or clang specific requests?

回答1:

It is possible, but it's questionable if you really should do that.

You would have to choose either to use libc++ or libstdc++ with both compilers.

libstdc++ is definitely the better one since clang can deal with it flawlessly, gcc has problems parsing several libc++ headers.

Something like this should make clang use gcc's libstdc++ on Mac OS X.

clang++ \
  -stdlib=libstdc++ \
  -nostdinc++ \
  -Qunused-arguments \
  -nodefaultlibs \
  <path to>x86_64-apple-darwin14/lib/libstdc++.a \
  <path to>x86_64-apple-darwin14/lib/libsupc++.a \
  <path to>lib/gcc/x86_64-apple-darwin14/5.2.0/libgcc.a \
  <path to>lib/gcc/x86_64-apple-darwin14/5.2.0/libgcc_eh.a \
  -lc \
  -Wl,-no_compact_unwind \
  -cxx-isystem <path to>x86_64-apple-darwin14/include/c++/5.2.0 \
  -cxx-isystem <path to>x86_64-apple-darwin14/include/c++/5.2.0/x86_64-apple-darwin14 \
  -mmacosx-version-min=10.7.0

I recommend to put this in a wrapper script, then pass CXX=clang++-libstdc++ to the boost build script.

Example wrapper script:

#!/bin/sh

ls -l "$@"

Wraps ls.