Using clang to compile R packages on Windows - c++

I've developing R packages that contain C++ code on Windows 10.
I wish to check for memory allocation errors. It sounds like the simplest path is to use clang++ with the -fsanitize=address option.
How do I configure R such that clang is the default compiler?
What I've done so far:
Install LLVM, adding binaries to the path
Set the following options in ~/.R/makevars:
CC = "path/to/llvm/bin/clang"
CXX = "path/to/llvm/bin/clang++"
CXX11 = "path/to/llvm/bin/clang++"
CXX14 = "path/to/llvm/bin/clang++"
CXXFLAGS = -O1 -g -fsanitize=address -fno-omit-frame-pointer
PKG_CXXFLAGS = -Og -fsanitize=address
LDFLAGS = -fsanitize=address
Within RStudio, run devtools::install(). I see:
- installing *source* package 'TreeTools' ...
** using staged installation
** libs
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c as_newick.cpp -o as_newick.o
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c int_to_tree.cpp -o int_to_tree.o
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c phangorn_bip.cpp -o phangorn_bip.o
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c renumber_tree.cpp -o renumber_tree.o
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c splits.cpp -o splits.o
"path/to/llvm/bin/clang++" -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG -I'C:/Users/ms609/Documents/R/win-library/4.0/Rcpp/include' -Og -Wall -pedantic -mtune=generic -fsanitize=address -Wno-deprecated-declarations -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign -c tree_shape.cpp -o tree_shape.o
path/to/llvm/bin/clang++ -shared -o TreeTools.dll tmp.def RcppExports.o TreeTools-init.o as_newick.o int_to_tree.o phangorn_bip.o renumber_tree.o splits.o tree_shape.o -LC:/PROGRA~1/R/R-40~1.0/bin/i386 -lR
tmp.def : fatal error LNK1107: invalid or corrupt file: cannot read at 0x1E50
clang++: error: linker command failed with exit code 1107 (use -v to see invocation)
no DLL was created
ERROR: compilation failed for package 'TreeTools'
R seems to have successfully compiled individual source files successfully using clang, but is failing to create a .dll.
What have I missed: do I need to do anything to configure Rcmd or Rtools to run with clang rather than the default gcc?

Related

compile simple github fails at ext submodule

i am trying to compile this git https://github.com/yapb/yapb locally
i am using ubuntu 64bit, and it says i must compile 32bit
i am using now
CC=clang CXX=clang meson build-clang
but get this error
FAILED: yapb.so.p/src_chatlib.cpp.o
clang -Iyapb.so.p -I. -I.. -fvisibility=hidden -flto
-fcolor-diagnostics -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall
-Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -Werror -std=c++14
-fno-exceptions -O3 -DVERSION_GENERATED -fno-threadsafe-statics
-fno-exceptions -fno-rtti -m32 -pedantic -fdata-sections
-ffunction-sections -mtune=generic -fno-builtin -funroll-loops
-fomit-frame-pointer -fno-stack-protector -fvisibility=hidden
-fvisibility-inlines-hidden -msse2 -mfpmath=sse -fPIC
-isystem../ext/crlib -isystem../ext -isystem../inc -isystem..
-isystem. -MD -MQ yapb.so.p/src_chatlib.cpp.o -MF
yapb.so.p/src_chatlib.cpp.o.d -o yapb.so.p/src_chatlib.cpp.o -c
../src/chatlib.cpp
In file included from ../src/chatlib.cpp:8:
In file included from ../inc/yapb.h:10:
In file included from ../ext/hlsdk/extdll.h:28:
In file included from ../ext/crlib/crlib/string.h:17:
../ext/crlib/crlib/array.h:15:10: fatal error: 'initializer_list' file not found
#include <initializer_list>```
Double-check the pre-requisites mentioned in YaPB Building the Bot page.
Try and open a regular CMD (instead of Powershell), making sure it inherits all your previous setups (meaning its %PATH% does reference g++.exe, pip.exe, and so on.

xgboost build error on CentOS 6.8

Operating System: CentOS 6.8
Compiler: gcc 4.8.2 and g++4.8.2
Steps to reproduce
Just follow the steps at installation guide
My steps
git clone --recursive https://github.com/dmlc/xgboost
git submodule init
git submodule update
cd xgboost
make -j4
Then I get the error below
[root#xxx]# make -j4
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/learner.o src/learner.cc >build/learner.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/logging.o src/logging.cc >build/logging.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/c_api/c_api.o src/c_api/c_api.cc >build/c_api/c_api.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/c_api/c_api_error.o src/c_api/c_api_error.cc >build/c_api/c_api_error.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/c_api/c_api_error.cc -o build/c_api/c_api_error.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/learner.cc -o build/learner.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/logging.cc -o build/logging.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/c_api/c_api.cc -o build/c_api/c_api.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/common/common.o src/common/common.cc >build/common/common.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/common/common.cc -o build/common/common.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/data/data.o src/data/data.cc >build/data/data.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/data/data.cc -o build/data/data.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/data/simple_csr_source.o src/data/simple_csr_source.cc >build/data/simple_csr_source.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/data/simple_csr_source.cc -o build/data/simple_csr_source.o
/tmp/ccNp7oXM.s: Assembler messages:
/tmp/ccNp7oXM.s:148: Error: expecting string instruction after `rep'
/tmp/ccNp7oXM.s:1796: Error: expecting string instruction after `rep'
/tmp/ccNp7oXM.s:4394: Error: expecting string instruction after `rep'
make: *** [build/data/simple_csr_source.o] Error 1
make: *** Waiting for unfinished jobs....
/tmp/ccnxYuhm.s: Assembler messages:
/tmp/ccnxYuhm.s:44: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:272: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:276: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:316: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:29012: Error: expecting string instruction after `rep'
make: *** [build/learner.o] Error 1
/tmp/ccyHo0ol.s: Assembler messages:
/tmp/ccyHo0ol.s:331: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:386: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:555: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:11407: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:17712: Error: expecting string instruction after `rep'
make: *** [build/c_api/c_api.o] Error 1
/tmp/cc3gD7Gv.s: Assembler messages:
/tmp/cc3gD7Gv.s:82: Error: expecting string instruction after `rep'
make: *** [build/data/data.o] Error 1
Is any suggestion for the root cause?
I am not familiar with xgboost, however from the error it seems obvious that some ASM code is not getting generated properly:
expecting string instruction after `rep'
The REP keyword prefix in ASM means "repeat this instruction a number of times (defined by the C register)".
However it could also be a problem with your toolchain. Actually, if the code that generates this error is not relying on inline ASM, it would seem likely that this is a toolchain error.
Some versions of binutils consider rep ret to be invalid, while it is in fact a valid x86-64 instruction.
Try upgrading to binutils 2.23.52.0.1

Why might make produce a different object file than the same command copy-pasted and entered manually?

Sort of related to my other question here, since this is also about building llvm.
When trying to get around a build failure in llvm, I noticed the following:
Output in terminal when building a single object file through make:
rp% make asan_posix.o
cd /tmp/llvm20150917-93899-y384cu && /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -f projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.iossim.dir/build.make projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o
Building CXX object projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o
cd /tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan && /usr/local/Library/ENV/4.3/clang++ -DASAN_DYNAMIC=1 -DASAN_HAS_EXCEPTIONS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-y384cu/include -I/tmp/llvm20150917-93899-1jg6jdx/include -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/.. -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -arch i386 -arch x86_64 -UNDEBUG -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -stdlib=libc++ -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-function-sections -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -ftls-model=initial-exec -o CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o -c /tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/asan_posix.cc
cd /tmp/llvm20150917-93899-y384cu && /Applications/Xcode-beta.app/Contents/Developer/usr/bin/make -f projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.osx.dir/build.make projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o
Building CXX object projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o
cd /tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan && /usr/local/Library/ENV/4.3/clang++ -DASAN_DYNAMIC=1 -DASAN_HAS_EXCEPTIONS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-y384cu/include -I/tmp/llvm20150917-93899-1jg6jdx/include -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/.. -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -arch i386 -arch x86_64 -UNDEBUG -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-function-sections -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -ftls-model=initial-exec -o CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o -c /tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/asan_posix.cc
rp% file CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o
CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o: Mach-O 64-bit object x86_64
rp% file CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o
CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o: Mach-O 64-bit object x86_64
Output when the same commands are entered manually:
rp% cd /tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan && /usr/local/Library/ENV/4.3/clang++ -DASAN_DYNAMIC=1 -DASAN_HAS_EXCEPTIONS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-y384cu/include -I/tmp/llvm20150917-93899-1jg6jdx/include -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/.. -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -arch i386 -arch x86_64 -UNDEBUG -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -stdlib=libc++ -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-function-sections -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -ftls-model=initial-exec -o CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o -c /tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/asan_posix.cc
rp% cd /tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan && /usr/local/Library/ENV/4.3/clang++ -DASAN_DYNAMIC=1 -DASAN_HAS_EXCEPTIONS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/tmp/llvm20150917-93899-y384cu/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan -I/tmp/llvm20150917-93899-y384cu/include -I/tmp/llvm20150917-93899-1jg6jdx/include -I/tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/.. -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -arch i386 -arch x86_64 -UNDEBUG -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -Wall -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-function-sections -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -ftls-model=initial-exec -o CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o -c /tmp/llvm20150917-93899-1jg6jdx/projects/compiler-rt/lib/asan/asan_posix.cc
rp% file CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o
CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o: Mach-O universal binary with 2 architectures
CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o (for architecture i386): Mach-O object i386
CMakeFiles/RTAsan_dynamic.iossim.dir/asan_posix.cc.o (for architecture x86_64): Mach-O 64-bit object x86_64
rp% file CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o
CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o: Mach-O universal binary with 2 architectures
CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o (for architecture i386): Mach-O object i386
CMakeFiles/RTAsan_dynamic.osx.dir/asan_posix.cc.o (for architecture x86_64): Mach-O 64-bit object x86_64
The searching I did didn't really help; I didn't write the makefile myself (cmake generated), and at least to my eyes there wasn't reason for make to print something that it wasn't executing.
Anyone have any idea what is going on?
Reproduction steps:
install homebrew if it isn't already installed
replace homebrew's llvm formula with the WIP one here
Run brew install llvm --with-clang --with-lldb --verbose --debug
wait for the build to fail and ask you what to do
Drop into a debug shell
cd to projects/compiler-rt/lib/asan
run make clean
run make asan_posix.o (or any of the other *.o files listed in make help
run file on the output file (in CMakeFiles/RTAsan_dynamic.(osx|iossim).dir/asan_posix.cc.o for me)
Repeat the above 3 steps, but copy-pasting the command instead of running make
Edit: Link to my environment in the shell and during the make process.
The solution to this question ended up being the same as the linked question. homebrew was changing compiler flags, so the commands that were printed weren't the ones being executed. The fix in the other question also happened to fix this.

What could cause clang to not find the unordered_map header?

I'm trying to compile a program I found on the web using Clang++. The Makefile generates this command:
clang++ -c -arch x86_64 -msse3 -std=c++11 -stdlib=libstdc++
-Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type
-Wno-non-virtual-dtor -Wno-exit-time-destructors -Wformat -Wmissing-braces
-Wparentheses -Wno-switch -Wunused-function -Wunused-label -Wno-unused-parameter
-Wunused-variable -Wunused-value -Wno-empty-body -Wuninitialized -Wunknown-pragmas
-Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion
-Wint-conversion -Wno-shorten-64-to-32 -Wenum-conversion -Wno-newline-eof
-Wno-c++11-extensions -Wno-logical-op-parentheses -Wno-trigraphs
-Wno-invalid-offsetof -Wno-sign-conversion -Wdeprecated-declarations
-fmessage-length=0 -fno-exceptions -fstrict-aliasing -fvisibility=hidden
-fvisibility-inlines-hidden -funsafe-math-optimizations -ftrapping-math -fno-rtti
-fpascal-strings -fasm-blocks -O3 -Iinclude/ src/main.cpp
But I get
src/main.cpp:23:10: fatal error: 'unordered_map' file not found
#include <unordered_map>
^
1 error generated.
If I compile a simple program that includes <unordered_map> running clang++ test.cpp, it compiles fine.
I'm on
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
I had the same issue when compiling glogg.
As the comments have pointed out. it was stdlib.
In the makefile after running qmake. Change this line from
CXXFLAGS = -g -Wextra -std=c++11 -DGLOGG_VERSION=\"`cat .tarball-version`\" -O2 -arch x86_64 -Wall -W $(DEFINES)
To this line below
CXXFLAGS = -g -Wextra -std=c++11 -stdlib=libc++ -DGLOGG_VERSION=\"`cat .tarball-version`\" -O2 -arch x86_64 -Wall -W $(DEFINES)
notice "-stdlib=libc++" was specified in the cxxflags. It's autospecified in the linker flags, I guess it also needs to be specified in for the C++ flags.
It says -Wno-c++11-extensions. What wrote that makefile?

C++11 link issue with pthread

I have wrote a simple code which uses c++11 thread. It compiles correct but when I try to run it I have the following error:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
I am using gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1). This is the output of the makefile which I am using
g++ -std=c++11 -DHAVE_CONFIG_H -I. -I../../../.. -I../../../.. -I/usr/local_machine/openmpi-1.6.5/include -pthread -DMPIPP_H -DENABLE_MPI=1 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -MT threadtest-threadtest.o -MD -MP -MF .deps/threadtest-threadtest.Tpo -c -o threadtest-threadtest.o `test -f 'threadtest.cc' || echo './'`threadtest.cc
mv -f .deps/threadtest-threadtest.Tpo .deps/threadtest-threadtest.Po
/bin/bash ../../../../libtool --tag=CXX --mode=link g++ -std=c++11 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -o threadtest threadtest-threadtest.o -pthread -L/usr/local_machine/openmpi-1.6.5/lib -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl ../../../../lib/libdunecommon.la -lm
libtool: link: g++ -std=c++11 -O3 -Wall -DNDEBUG -funroll-loops -finline-functions -pthread -fomit-frame-pointer -ffast-math -mfpmath=sse -msse3 -o threadtest threadtest-threadtest.o -pthread -Wl,--export-dynamic -L/usr/local_machine/openmpi-1.6.5/lib /usr/local_machine/openmpi-1.6.5/lib/libmpi.so -lrt -lnsl -lutil -ldl ../../../../lib/.libs/libdunecommon.a -llapack -lblas -lgfortran -lquadmath -lm -pthread -Wl,-rpath -Wl,/usr/local_machine/openmpi-1.6.5/lib -Wl,-rpath -Wl,/usr/local_machine/openmpi-1.6.5/lib
As you can see there is the flag -pthread. What am I doing wrong? Because if I compile a simple code as
g++ threadstest.cc -o threadstest -pthread -std=c++11
everything works fine therefore in my makefile there is something which interferes with -pthread but I don't understand what it is.
Additional information: a workaround which works is to add -Wl,--no-as-needed at the linking stage.
the answer for similar question "Compiling multithread code with g++ (-Wl,--no-as-needed NOT working)"
is
-pthread is a flag for the compiler, not the linker, the right one for the linker is -lpthread