clang: warning: no such sysroot directory: '-mmacosx-version-min=10.5' on compiling LLVM (3.9.0) - c++

I am compiling LLVM (3.9.0) using CMake (3.6.2) on my Mac (OsX) using GCC, but somehow I am getting the following error with following GCC configuration
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
[50%] Building C object projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/eprintf.c.o
clang: warning: no such sysroot directory: '-mmacosx-version-min=10.5'
/Users/Ritzy/llvm_src/llvm-3.9.0.src/projects/compiler-rt/lib/builtins/eprintf.c:14:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
make[2]: *** [projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/eprintf.c.o] Error 1
make[1]: *** [projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.eprintf.dir/all] Error 2
make: *** [all] Error 2
I am using following CMake command:
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
cmake --build .
I spent hours figuring out what was wrong. Even tried to using gcc6 and clang but in vain.

Here's an example of what the command line flags supplied to a MacOS/X clang invocation might look like:
-pipe -stdlib=libc++ -std=c++11 -stdlib=libc++ -O2 -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC $(DEFINES)
Note in particular this part:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7
-isysroot tells the compiler where to look for header files, and then the next argument -mmacosx-version-min=10.7 tells it what minimum version of MacOS/X to maintain backwards compatibility with.
In your case, your CMake invocation probably isn't specifying a value for the -isysroot argument, instead it probably has something like this:
-isysroot -mmacosx-version-min=10.5
... where the path that was intended to be supplied after the -isysroot flag has been left blank (i.e. an empty string) for some reason, and that is why "-mmacosx-version-min=10.5" is being interpreted as a path to look for header files in (which of course will not work).
As to why the path argument was left blank, that is something you'll have to investigate on your own.

Related

c++: error: unrecognized command line option ‘-std=c++17’

[ 25%] Building CXX object CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o
/usr/bin/c++ -I/home/jeong/다운로드/dlib-master -I"/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples/path to dlib install dir/include" -std=c++17 -msse3 -fopenmp -Wall -Wextra -o CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o -c /home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples/linreg_dlib.cc
c++: error: unrecognized command line option ‘-std=c++17’
make[2]: *** [CMakeFiles/linreg-dlib.dir/linreg_dlib.cc.o] error 1
make[2]: Leaving directory `/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples'
make[1]: *** [CMakeFiles/linreg-dlib.dir/all] error 2
make[1]: Leaving directory `/home/jeong/바탕화면/9781789955330_Code/Chapter01/dlib_samples'
make: *** [all] error 2
c++: error: unrecognized command line option ‘-std=c++17’
I am running the practice code using the dlib library.
It runs until'cmake', but the above error appears during'make' process. Need to update gcc?
The gcc version is shown below.
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
How to do it if you need to update the version
I wonder.
The GCC releases page (https://www.gnu.org/software/gcc/releases.html) says that gcc 4.8.5 was released on June 23, 2015.
The GCC developers are really good, but shipping C++17 support two years before C++17 was completed is beyond good.
That compiler may support -std=c++1z for some C++17 features, though.
As others have mentioned your compiler is too old for C++17.
It sounds like you are on either RHEL 7 or CentOS 7. Those OSes support installation of "Developer Toolsets" with newer versions of the compiler and toolchain (in addition to the standard system compiler).
This might be an option for you.
For RHEL 7 see: https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/10/
For CentOS see: https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/

"Make" fails with Clang error - how do I get the error from Clang?

Main question is: How do I get the clang error out of make?
I have been trying to follow these instructions to install GLEW. On second look I've seen that GLEW might not really be necessary on Mac OS X, but I'd still like to find out how to get the error from the problem I was having. (I am not very experienced with make and could not make any similar online solutions work).
Theoretically I should download GLEW, unzip, and run 'make' in the file. This is the output of make:
$ make
cc -dynamiclib -install_name /usr/local/lib/libGLEW.2.1.0.dylib -current_version 2.1.0 -compatibility_version 2.1 -o lib/libGLEW2.1.0.dylib tmp/darwin/default/shared/glew.o -framework OpenGL
ld: malformed file
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//OpenGLframework/OpenGL.tbd:4:18: error: unknown enumerated scalar
platform: zippered
^~~~~~~~
file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Framework//OpenGL.framework/OpenGL.tbd'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [lib/libGLEW.2.1.0.dylib] Error 1
Make -n shows that this is just the first command and it pretty much immediately fails. I have tried make V=1, make VERBOSE=1, and make SHELL='sh -x', but they don't give me additional detail about the clang error. I've also tried running the cc command with -v:
$ cc -v -dynamiclib -install_name /usr/local/lib/libGLEW.2.1.0.dylib -current_version 2.1.0 -compatibility_version 2.1 -o lib/libGLEW2.1.0.dylib tmp/darwin/default/shared/glew.o -framework OpenGL
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -dylib -dylib_compatibility_version 2.1 -dylib_current_version 2.1.0 -arch x86_64 -dyib_install_name /usr/local/lib/libGLEW.2.1.0.dylib -macosx_version_min 10.14.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -o lib/libGLEW.2.1.0.dylib tmp/darwin/default/shared/glew.o -framework OpenGL -L/usr/local/lib -lSystem / Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchains/usr/lib/clang/9.1.0/lib/darwin/libclang_rt.osx.a
ld: malformed file
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//OpenGLframework/OpenGL.tbd:4:18: error: unknown enumerated scalar
platform: zippered
^~~~~~~~
file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Framework//OpenGL.framework/OpenGL.tbd'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [lib/libGLEW.2.1.0.dylib] Error 1
I don't think I am actually managing to get the real error out of clang. So how do I do that?
It is
Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -dylib -dylib_compatibility_version 2.1 -dylib_current_version 2.1.0 -arch x86_64 -dyib_install_name /usr/local/lib/libGLEW.2.1.0.dylib -macosx_version_min 10.14.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -o lib/libGLEW.2.1.0.dylib tmp/darwin/default/shared/glew.o -framework OpenGL -L/usr/local/lib -lSystem / Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchains/usr/lib/clang/9.1.0/lib/darwin/libclang_rt.osx.a
command that fails, which is ld, not clang. You can run this command separately to get the same error message.
And
ld: malformed file
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//OpenGLframework/OpenGL.tbd:4:18: error: unknown enumerated scalar
platform: zippered
^~~~~~~~
file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Framework//OpenGL.framework/OpenGL.tbd'
is linker's error message. Unfortunately, I'm not familiar with compilation process on Mac, so can't advice how to fix it.

Cross compiling with clang on cmake, linker does not support armelf_linux_eabi

Here's my cmake toolchain file to cross compile for arm linux:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CLANG_TARGET_TRIPLE arm-linux-gnueabihf)
set(GCC_ARM_TOOLCHAIN_PREFIX ${CLANG_CLANG_TARGET_TRIPLE})
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
Here's the problem when I execute cmake with it:
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/lz/orwell/gtk/build/armlinux/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_8132a/fast"
/usr/bin/make -f CMakeFiles/cmTC_8132a.dir/build.make CMakeFiles/cmTC_8132a.dir/build
make[1]: Entering directory '/home/lz/orwell/gtk/build/armlinux/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8132a.dir/testCCompiler.c.o
/usr/bin/clang --target=arm-linux-gnueabihf -o CMakeFiles/cmTC_8132a.dir/testCCompiler.c.o -c /home/lz/orwell/gtk/build/armlinux/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_8132a
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_8132a.dir/link.txt --verbose=1
/usr/bin/clang --target=arm-linux-gnueabihf -rdynamic CMakeFiles/cmTC_8132a.dir/testCCompiler.c.o -o cmTC_8132a
/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe
clang: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/cmTC_8132a.dir/build.make:97: recipe for target 'cmTC_8132a' failed
make[1]: *** [cmTC_8132a] Error 1
make[1]: Leaving directory '/home/lz/orwell/gtk/build/armlinux/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_8132a/fast' failed
make: *** [cmTC_8132a/fast] Error 2
It looks like it's trying to use /bin/ld instead of clang's linker (is there one?). I know that there exists CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN but I don't know the path to include and preferably I didn't want to include any paths, I'd like to make it work without path specification.
So, how to specify a compatible linker?

Unable to Change Default Linker in CMake

I am trying to change my linker to ld.gold so that I can build LLVM and
CLANG faster. I have changed my environment variable with:
export LD=ld.gold
and I have changed CMAKE_LINKER in ccmake to /usr/bin/ld.gold. However,
when I generate the files, my linker is detected as GNU ld. Running top
during compilation confirms that ld is running rather than gold.
When editing the CMake Link Executable variable to:
cmake -DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" -G "Unix Makefiles" ../llvm
I receive the following error:
/usr/bin/ld.gold: -Werror=date-time: unknown option
/usr/bin/ld.gold: use the --help option for usage information
utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/build.make:94: recipe for target 'bin/llvm-PerfectShuffle' failed
make[2]: *** [bin/llvm-PerfectShuffle] Error 1
CMakeFiles/Makefile2:13983: recipe for target 'utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all' failed
I'm on Ubuntu 16.04, but I have had the same problem on Arch Linux.
Thank You.
CMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold will pass -fuse-ld=gold to the compiler, which will properly use the gold linker.

Error building and compiling GCC 5.2.0 from scratch on Vortex86DX

In order to upgrade a VortexDX86 custom linux with a gcc 3.2.3 compiler, I´m trying to built the GCC 5.2.0 compiler to support the latest C++ 11 standard.
I have downloaded its source code from gcc.gnu.org and did the standard linux package builder based on this link.
$ mkdir ../gcc-build
$ cd ../gcc-build
$ ../gcc-5.2.0/configure --prefix=/usr --disable-multilib --with-system-zlib --enable-languages=c,c++
The configuration runs fine. The I do:
$ make
And I´m getting the following error:
make[3]: Entering directory `/home/ftp/pub/gcc-5.2.0/host-i586-pc-linux-gnu/gcc'
g++ -c -g -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual -fno-common -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I../.././gcc -I../.././gcc/build -I../.././gcc/../include -I../.././gcc/../libcpp/include \
-o build/genmddeps.o ../.././gcc/genmddeps.c
cc1plus: warning: -Wmissing-format-attribute ignored without -Wformat
In file included from ../../gcc/genmddeps.c:19:
../../gcc/system.h:201:19: string: No such file or directory
../../gcc/system.h:218:22: algorithm: No such file or directory
../../gcc/system.h:219:20: cstring: No such file or directory
../../gcc/system.h:220:20: utility: No such file or directory
../../gcc/system.h:249:19: cstdlib: No such file or directory
make[3]: *** [build/genmddeps.o] Error 1
make[3]: Leaving directory `/home/ftp/pub/gcc-5.2.0/host-i586-pc-linux-gnu/gcc'
make[2]: *** [all-stage1-gcc] Error 2
make[2]: Leaving directory `/home/ftp/pub/gcc-5.2.0'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/ftp/pub/gcc-5.2.0'
make: *** [all] Error 2
After that the make procedure aborts. I´ve installed all the dependencies (tcl, expect, dejagnu, perl, m4, gmp, mpfr and mpc) and I don´t know what is missing.
As said, the original Vortex linux has a gcc 3.2.3 compiler version.
I need to solve that but I don´t know where to start from. It seens to have confusion with the own gcc libraries....
Help appreciated to solve that.
You need a working C++ compiler to build recent releases of GCC, and you don't seem to have that (your GCC 3.2.3 seems to be missing the C++ standard library headers).
I suggest that you use the existing compiler to build GCC 4.7.4 (which can still be built by a C compiler) to get a working C++ compiler. Then use GCC 4.7.4 to build GCC 5.2
Bad. This did not solved the issue.... I´ve followed all the steps and the same error remains...
It happens maybe because you do not know enough your Operating System or maybe because you don't know to much about gcc
Here is step-by-step how to compile GCC-5.2.0 from scratches On Ubuntu.
1)
mkdir $HOME/gcc-5.2.0
2)
cd gcc-5.2.0/
3)
sudo apt-get install libmpfr-dev libgmp3-dev libmpc-dev flex bison gcc-multilib texinfo
4)
wget http://ftp.gnu.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.gz
5)
tar -xzvf gcc-5.2.0.tar.gz
6)
cd gcc-5.2.0/
7)
mkdir build
8)
cd build/
9)
../configure --enable-multilib --disable-checking --enable-languages=c,c++ \
--enable-multiarch --enable-shared --enable-threads=posix \
--program-suffix=5.2 --with-gmp=/usr/local/lib --with-mpc=/usr/lib \
--with-mpfr=/usr/lib --without-included-gettext --with-system-zlib \
--with-tune=generic \
--prefix=$HOME/install/gcc-5.2.0
10)
make -j4
11)
make install