Using g++ with libc++ - g++

It's quite easy to get clang++ to use GCC's libstdc++ (-stdlib=stdc++), but how can I do the converse? On OS X Mavericks, the c++ system library is libc++, which means that basically libstdc++ cannot be used (if you mix with other c++ libraries such as boost that have been compiled with libc++). So, roughly, that means G++ is not usable... Unless I can ask it to use libc++ rather than libstdc++.
Thanks.
The script I use (EDIT)
I'm using the following script, g++-libc++, to run g++ on top of libc++, on Mac OS X with MacPorts (hence the -mp names.
#! /bin/sh
clangxx=clang++-mp-3.5
gxx=g++-mp-4.9
libcxx_includes=$($clangxx -print-search-dirs |
perl -ne 's{^libraries: =(.*)}{$1/../../../} && print')
exec $gxx -std=c++11 \
-isystem ${libcxx_includes}/include/c++/v1 \
-nostdinc++ -nodefaultlibs \
-lc -lc++ -lc++abi -lgcc_s.10.5 \
-Wl,-no_compact_unwind \
"$#"

Something like:
g++ -std=c++0x -nostdinc++ -nodefaultlibs -lc -isystem <path_to>/include/c++/v1 -lc++ -lc++abi -lgcc_s.10.5

Related

Building LLVM with cmake. Does -D_GLIBCXX_USE_CXX11_ABI=0 get overridden?

I try to build LLVM.
This is the way I try …
mkdir -p src/llvm-$(LLVM_VERSION).src/build
cd src/llvm-$(LLVM_VERSION).src/build && \
$(CMAKE) -GNinja \
-DCMAKE_INSTALL_PREFIX=$(BUNDLE) \
-DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -static-libgcc -static-libstdc++ -l:libstdc++.a" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
-DLLVM_PARALLEL_COMPILE_JOBS=$(BUILD_JOBS) \
-DLLVM_PARALLEL_LINK_JOBS=2 \
-DLLVM_USE_CRT_RELEASE=MD \
-DLLVM_USE_CRT_DEBUG=MDd \
-DLLVM_STATIC=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_BUILD_LLVM_C_DYLIB=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_UNWIND_TABLES=OFF \
-DLLVM_ENABLE_RTTI=ON \
.. && \
$(CMAKE) --build . && \
$(CMAKE) --build . --target install
You can see -D_GLIBCXX_USE_CXX11_ABI=0 in -DCMAKE_CXX_FLAGS. After LLVM finished compiling, libLLVM*.a still contain abi:cxx11 symbols.
llvm-config reveals, llvm build process completely ignored "-D_GLIBCXX_USE_CXX11_ABI=0" flag.
> ./bundle/bin/llvm-config --cxxflags
-I/home/leonard/Documents/Develop/build_as_deps/bundle/include -std=c++11 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Do you have an idea how to build llvm in a way that disables abi:cxx11 symbols and prevents "-D_GLIBCXX_USE_CXX11_ABI=0" to be overridden?
It looks like you're confusing the cmake options (which are specified with via -D) with C/C++ compiler macro (which are also specified via -D, but to compiler). cmake happily ignored your -D_GLIBCXX_USE_CXX11_ABI, because it's not a cmake option (and you should see a warning about this, that the value is unused by the build system).
Since you need to add extra macro definition, you'd need to change CMAKE_CXX_FLAGS cmake variable.

What does the -DQT_WEBKIT flag mean in g ++?

The same project is assembled on different versions of the OS with different flags.
What is this flag?
First OS:
-g++ -c -pipe -g -D_REENTRANT -Wall -W -Wno-unknown-pragmas -DQT_WEBKIT -D_TESTR ...
Other OS:
+g++ -c -pipe -g -D_REENTRANT -Wall -W -Wno-unknown-pragmas -D_TESTR
The -D option is a preprocessor option and is documented in section 3.13 Preprocessor Options of the GCC Manual. (You can also always just run gcc --help or g++ --help to get help for the options.)
The -D<name>[=<value>] option #defines the macro <name> to have the value <value> (or 1 if the value <value> is not provided).
So, in your case, it defines the three macros _REENTRANT, QT_WEBKIT, and D_TESTR to the value 1, in other words, it is exactly equivalent to having
#define _REENTRANT 1
#define QT_WEBKIT 1
#define D_TESTR 1
prepended to the file being compiled.

Why does ghc in its own build pass contradictory optimisation flags?

I'm building a GHC from source again (7.8 on ARM, as there's no binary version of that), and noticed it does this at some point:
"inplace/bin/ghc-stage1" -static -optc-DTHREADED_RTS -optc-DDEBUG -H32m \
-O -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header \
-Iincludes/dist-ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS \
-package-name rts -dcmm-lint -i -irts -irts/dist/build \
-irts/dist/build/autogen -Irts/dist/build -Irts/dist/build/autogen \
-O2 -O0 -c rts/StgMiscClosures.cmm -o rts/dist/build/StgMiscClosures.thr_debug_o
Well, that's -O, -O2 and -O0 in a single command!
What is the reason for this, and which flag takes precedence anyway in such a case?
processArgs processes command-line arguments left-to-right (see process in CmdLineParser.processArgs. Furthermore, the semantics of the -O flags is such that each of them turns on/off a certain subset of individual optimizations (see updOptLevel). So in your example -O0 "wins" since it overwrites the effects of -O and -O2.

Gcc error while compiling option -fPIC

I'm reading a book but I get one error while compiling with this code.
$ rm -f injection.dylib
$ export PLATFORM=/Developer/Platforms/iPhoneOS.platform
$ $PLATFORM/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 \
-c -o injection.o injection.c \
-isysroot $PLATFORM/Developer/SDKs/iPhoneOS5.0.sdk \ -fPIC
$ $PLATFORM/Developer/usr/bin/ld \ -dylib -lsystem -lobjc \
-o injection.dylib injection.o \
-syslibroot $PLATFORM/Developer/SDKs/iPhoneOS5.0.sdk/
I've some trouble especially in this line:
$PLATFORM/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 \
-c -o injection.o injection.c \
-isysroot $PLATFORM/Developer/SDKs/iPhoneOS5.0.sdk \ -fPIC
This is the error
arm-apple-darwin10-llvm-gcc-4.2: -fPIC: No such file or directory
how can I solve... what does it means?
It means you mistyped the command line:
stieber#gatekeeper:~$ gcc \ -fPIC
gcc: error: -fPIC: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Seems the \ in the middle of the line makes gcc (and probably the llvm-gcc as well) stop considering arguments as options and always treats them as filenames.
stieber#gatekeeper:~$ gcc -fPIC
gcc: fatal error: no input files
compilation terminated.
gives the expected result.

What does the -I option do in a g++ call?

I'm having a hard time finding good documentation on the most common g++ options. I have the following g++ command and I'm trying to understand it well:
g++ q1.cpp -o q1 -I/usr/local/include/opencv -L/usr/local/lib -lm -lopencv_core -lopencv_highgui -lopencv_calib3d -lopencv_imgproc
What does the -I option do?
-I adds to the path for searching for include files.
-l links to a particular library. (e.g. -lm links libm which is math)
It's not for a library I think it's only for include files. (It's a i not a l, l it's for libraries)