Couldn't build llvm with gcc on archlinux - c++

I tried to build llvm and got an error message related to stdlib.
I searched the cause with error message but
I don't know c/c++ well, so I couldn't understand what happened or how to fix this.
Please tell me what this means and what happened in my environment.
1: What I did
I tried to build llvm with below.
git clone https://github.com/llvm/llvm-project -b release/12.x
cd llvm-project
mkdir build
cd build
cmake -G Ninja \
-DDEFAULT_SYSROOT=${HOME}/riscv_github/riscv64-unknown-elf \
-DCMAKE_BUILD_TYPE="Debug" \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64;RISCV" \
-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" \
../llvm
ninja
And got an error message below.
[8/4685] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/xxx/github.com/llvm-myriscvx120/build/lib/Support -I/home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support -I/home/xxx/github.com/llvm-myriscvx120/build/include -I/home/xxx/github.com/llvm-myriscvx120/llvm/include -isystem /usr/bin/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color -g -std=c++14 -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/ARMBuildAttrs.cpp.o -c /home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support/ARMBuildAttrs.cpp
In file included from /usr/include/c++/12.1.1/cstdlib:75,
from /usr/include/c++/12.1.1/bits/stl_algo.h:69,
from /usr/include/c++/12.1.1/algorithm:61,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/ADT/Hashing.h:51,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/ADT/ArrayRef.h:12,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/Support/ELFAttributes.h:12,
from /home/xxx/github.com/llvm-myriscvx120/llvm/include/llvm/Support/ARMBuildAttributes.h:21,
from /home/xxx/github.com/llvm-myriscvx120/llvm/lib/Support/ARMBuildAttrs.cpp:9:
/usr/include/stdlib.h:579:5: error: expected initializer before ‘__attr_dealloc_free’
579 | __attr_dealloc_free;
| ^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:583:14: error: expected initializer before ‘__attr_dealloc’
583 | __THROW __attr_dealloc (reallocarray, 1);
| ^~~~~~~~~~~~~~
/usr/include/stdlib.h:606:35: error: expected initializer before ‘__attribute_alloc_align__’
606 | __THROW __attribute_malloc__ __attribute_alloc_align__ ((1))
| ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:812:6: error: expected initializer before ‘__attr_dealloc_free’
812 | __attr_dealloc_free __wur;
| ^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:961:3: error: expected initializer before ‘__fortified_attr_access’
961 | __fortified_attr_access (__write_only__, 1, 3)
| ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:1016:30: error: expected initializer before ‘__fortified_attr_access’
1016 | __THROW __nonnull ((2)) __fortified_attr_access (__write_only__, 2, 3);
| ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12.1.1/cstdlib:171:11: error: ‘wcstombs’ has not been declared in ‘::’
171 | using ::wcstombs;
| ^~~~~~~~
ninja: build stopped: subcommand failed.
It seemed to me that gcc is broken, so I tried to build llvm with gcc-11(g++-11) and gcc-10(g++-10), and got the same error.
After that, I checkout to the release/11.x branch and try to build with the same cmake options.
Then the build step started and it seems well.
So I tried another branches, release/13.x, release/14.x, release/15.x and they wouldn't work.
2: My Env
$ uname -a
Linux arch-x13 5.18.16-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 03 Aug 2022 11:25:04 +000 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 12.1.1 20220730
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cmake --version
cmake version 3.23.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).**strong text**
$ ninja --version
1.11.0
Edit:
I could build llvm of release/12.x branch at Ubuntu20.04 machine with gcc-9 and gcc-10, so I tagged archlinux to this question.
I also tried some version of c++ standard, 20, 17 and 14 using the option DCMAKE_CXX_STANDARD=, but it wouldn't help.

I could find the cause with the help of my colleague.
The reason is the -isystem /usr/bin/include option.
In my laptop, the path existed surely, but I don't remember what this is, and pacman and paru knew neither...

Related

Problems in pktgen build

DPDK and PKTGEN version 20.07 , and have followed all commands in the install.md .
I get this warning which is being treated as an error
`
FAILED: lib/common/3d47a30##common#sta/core_info.c.o
cc -Ilib/common/3d47a30##common#sta -Ilib/common -I../lib/common -I/usr/local/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -Werror -O3 -march=native -mavx -mavx2 -DALLOW_EXPERIMENTAL_API -D_GNU_SOURCE -Wno-pedantic -Wno-format-truncation -fPIC -include rte_config.h -march=native -MD -MQ 'lib/common/3d47a30##common#sta/core_info.c.o' -MF 'lib/common/3d47a30##common#sta/core_info.c.o.d' -o 'lib/common/3d47a30##common#sta/core_info.c.o' -c ../lib/common/core_info.c
In file included from ../lib/common/core_info.c:27:
../lib/common/core_info.h: In function ‘lcore_mask’:
../lib/common/core_info.h:29:11: error: implicit declaration of function ‘rte_get_main_lcore’; did you mean ‘rte_get_next_lcore’? [-Werror=implicit-function-declaration]
29 | lid = rte_get_main_lcore();
| ^~~~~~~~~~~~~~~~~~
| rte_get_next_lcore
cc1: all warnings being treated as errors
Compiling C object 'app/a172ced##pktgen#exe/pktgen-arp.c.o'.
ninja: build stopped: subcommand failed.
`
Mentioned above. I have also tried with 20.02 and the latest 22.11.
based on live debug and discussion, the solution to problem is suggested as
use dpdk release download from here
Download pktgen dpdk hosted project link
As mentioned in the comment, the thumb rule is
The right way to build pktgen is following same order (year of release) of DPDK. That is if you have pktgen-dpdk-pktgen-22.2.0.tar.gz use at least dpdk 22.01 or higher. If you have pktgen pktgen-dpdk-pktgen-20.11.3. use DPDK 20.11.1 or higher
Always use release version major number of pktgen and dpdk to be same. This has more chance of getting it to work.

How to use Clang's CUDA compiler?

I am on Ubuntu 17.10. I installed the CUDA 9.1 SDK from NVIDIA.
This is what I tried:
~/GrinGoldMiner/src/Cudacka$ clang++-5.0 -Wl,--cuda-path=/usr/local/cuda-9.1 kernel.cu
clang: error: cannot find libdevice for sm_20. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
clang: error: cannot find CUDA installation. Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.
clang: error: cannot find CUDA installation. Provide its path via --cuda-path, or pass -nocudainc to build without CUDA includes.
Obviously it doesn't work. It seems like the linker flags are not getting passed. How can I pass them correctly?
It seems clang++-5.0 does not support CUDA 9.X ...
clang++ is able to compile CUDA kernels with CUDA 8.0:
$ clang++-5.0 -O0 -g --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-8.0 -o t1 t1.cu -L/usr/local/cuda-8.0/lib64 -lcudart
But when using CUDA 9.X I get the same error as you:
$ clang++-5.0 --cuda-gpu-arch=sm_50 --cuda-path=/usr/local/cuda-9.0 -o t1 t1.cu -L/usr/local/cuda-9.0/lib64 -lcudart
clang: error: cannot find libdevice for sm_50. Provide path to different CUDA installation via --cuda-path, or pass -nocudalib to build without linking with libdevice.
They added support for Volta (sm_70) and CUDA 9.0 in this commit: 6d4cb40.
In 2017, this was only available on master branch, and you would have confirmed it like this:
$ git clone https://github.com/llvm-mirror/clang.git
$ cd clang/
$ git branch --contains 6d4cb40
* master
$ git checkout release_50
Branch release_50 set up to track remote branch release_50 from origin.
Switched to a new branch 'release_50'
$ git log | grep 6d4cb40
$ (output was empty)
Note that clang (7.0.0, released September 2018) supports CUDA 7.0 through 9.2.
I tried to build the GrinGoldMiner's Cudacka under Ubuntu 17.10, and all I had to do was:
make
This generated two commands on my machine (after some cleanup):
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o cudacka.o -c kernel.cu
/usr/local/cuda-9.1/bin/nvcc -ccbin g++ -m64 -Xcompiler -fpermissive -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 -o Cudacka.exe cudacka.o
And they finished successfully generating executable Cudacka.exe.
If you are interested specifically in clang:
When I tried to replace g++ with clang++-5.0, I got this error:
nvcc fatal : The version ('50000') of the host compiler ('clang') is not supported
If I use -std=c++11 -ccbin clang++ instead of -ccbin g++, I get this error:
kernel.cu(397): error: explicit instantiation definition directive for __global__ functions with clang host compiler is not yet supported
So, I doubt that you can use clang to compile that code for Ubuntu.

How to force Bazel to use gcc?

Ubuntu 17.10
GCC Version: 5.4
Bazel Version: 0.9.0
TensorFlow: r1.5
CUDA 8.0 / cuDNN 6 / GTX 1080 Ti
How do I make Bazel use gcc for building TensorFlow from source?
While building, its running into compiler errors like:
error: 'errno' was not declared in this scope
while (nanosleep(&ts, &ts) != 0 && errno == EINTR) {}
Setting --verbose_failures flag, it shows that its not using /usr/bin/gcc-5 or /usr/bin/gcc for compiling
external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -fPIE -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections -g0 -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK '-march=native' '-std=c++11' -g0 -MD -MF
Searching online, I found that the path to gcc and CC, CXX variables must be set in tools/cpp/CROSSTOOL. But where exactly is tools/cpp/CROSSTOOL?? How do I force bazel to use gcc-5?
I know next to nothing about cuda and tensorflow, but tensorflow doesn't use the same C++ toolchain that bazel autoconfigures when compiling with cuda, so the CC env variable trick won't work. The file crosstool_wrapper_driver_is_not_gcc is just a shell wrapper that could in theory still call your gcc (or it will be cuda). I'd run bazel with --subcommands to see the complete invocation of the failing action, then reproduce without bazel, and then go from there.

Autoconf rejected by C++11 library accepted by compiler, reject by preprocessor

I'm trying to integrate rapidcheck into an existing C++ codebase. The README says it requires C++11 and relies heavily on its features. The existing codebase uses automake to build all of the dependencies. Here is how I am adding the dependency into configure.ac:
CXXFLAGS="$CXXFLAGS -Wall -Werror -Wno-missing-braces -std=c++11"
CXXFLAGS="$CXXFLAGS -I/home/chris/dev/rapidcheck/include"
CXXFLAGS="$CXXFLAGS -I/home/chris/dev/rapidcheck/include/rapidcheck"
AC_CHECK_HEADERS(
[rapidcheck.h],
[AC_CHECK_LIB([rapidcheck], [main],[], [])],
[])
Here is the error I am getting when I run the configure script:
checking rapidcheck.h usability... yes
checking rapidcheck.h presence... no
configure: WARNING: rapidcheck.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: rapidcheck.h: proceeding with the compiler's result
checking for rapidcheck.h... yes
checking for main in -lrapidcheck... no
contents of config.log
3501 configure:22873: checking rapidcheck.h usability
3502 configure:22873: g++ -std=c++11 -c -g -O2 -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wall -Werror -Wno-missing-braces -std=c++11 -I/home/chris/dev/rapidcheck/include -I/home/chris /dev/rapidcheck/include/rapidcheck -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS conftest.cpp >&5
3503 configure:22873: $? = 0
3504 configure:22873: result: yes
3505 configure:22873: checking rapidcheck.h presence
3506 configure:22873: g++ -std=c++11 -E -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS conftest.cpp
3507 conftest.cpp:58:24: fatal error: rapidcheck.h: No such file or directory
3508 compilation terminated.
I think it has something to do with not having an up to date C++ compiler.
Here is the version of C++ I have installed:
chris#chris:~/dev/bitcoin$ g++ --version
g++ (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Which I THINK is C++11 compatible.
This has nothing to do with automake, it has to do with autoconf.
In particular, you should be able to ignore this warning in general because autoconf accepts the compiler output better than the preprocessor. As someone already said in the comments, CPPFLAGS should be used to pass -I flags for the preprocessor to find the headers, but in this case it's really not that important, given that those flags should not be set in configure.ac at all (but rather be passed from the outside since the install location is defined by the user.)

Building Boost 1.59 with Intel C++ Compiler 15.0 in Centos 7

I am trying to build Boost 1.59 with Intel C++ Compiler 15.0 in Centos 7. I am using the below command.
./bootstrap.sh --without-libraries=mpi,python
./b2 toolset=intel-15.0 address-model=64 cxxflags="-std=c++11" --layout=versioned link=static variant=debug,release
I got the below error in building Boost.Log. Could you please help? I tried to compile with GCC 4.8 and it works. Is it a bug in Intel C++ Compiler?
intel-linux.compile.c++ bin.v2/libs/log/build/intel-linux-15.0/debug/link-static/log-api-unix/threading-multi/default_filter_factory.o
./boost/fusion/algorithm/query/detail/find_if.hpp(208): internal error: assertion failed at: "shared/cfe/edgcpfe/lower_il.c", line 18968
return recursive_call(iter, found());
^
compilation aborted for libs/log/src/default_filter_factory.cpp (code 4)
"icpc" -c -xc++ -O0 -g -w1 -inline-level=0 -pthread -m64 -fvisibility=hidden -std=c++11 -wd177,780,2196,1782,193,304,981,1418,411,734,279 -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_STATIC_LINK=1 -DBOOST_FILESYSTEM_STATIC_LINK=1 -DBOOST_LOG_SETUP_BUILDING_THE_LIB=1 -DBOOST_LOG_USE_AVX2 -DBOOST_LOG_USE_NATIVE_SYSLOG -DBOOST_LOG_USE_SSSE3 -DBOOST_LOG_WITHOUT_EVENT_LOG -DBOOST_SPIRIT_USE_PHOENIX_V3=1 -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_DONT_USE_CHRONO=1 -DBOOST_THREAD_POSIX -DBOOST_THREAD_USE_LIB=1 -DDATE_TIME_INLINE -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=600 -I"." -c -o "bin.v2/libs/log/build/intel-linux-15.0/debug/link-static/log-api-unix/threading-multi/default_filter_factory.o" "libs/log/src/default_filter_factory.cpp"
...failed intel-linux.compile.c++ bin.v2/libs/log/build/intel-linux-15.0/debug/link-static/log-api-unix/threading-multi/default_filter_factory.o...
intel-linux.compile.c++ bin.v2/libs/log/build/intel-linux-15.0/debug/link-static/log-api-unix/threading-multi/matches_relation_factory.o
./boost/fusion/algorithm/query/detail/find_if.hpp(208): internal error: assertion failed at: "shared/cfe/edgcpfe/lower_il.c", line 18968
return recursive_call(iter, found());
^
compilation aborted for libs/log/src/matches_relation_factory.cpp (code 4)