Why can't clang++ on Ubuntu 14.04 find <iostream> - ubuntu-14.04

I am compiling this program:
#include <iostream>
int main()
{
}
This command
g++ -c hello_world.cpp
works.
This command
clang++ -c hello_world.cpp
gives this error:
hello_world.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
Doing:
clang++ -c hello_world.cpp -v
gives:
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.1
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
"/usr/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name hello_world.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.24 -v -coverage-file /home/user/code/cpp/StackOverflow_questions/hello_world.o -resource-dir /usr/bin/../lib/clang/3.4 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4/include -internal-externc-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/user/code/cpp/StackOverflow_questions -ferror-limit 19 -fmessage-length 202 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o hello_world.o -x c++ hello_world.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++
/usr/local/include
/usr/bin/../lib/clang/3.4/include
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
hello_world.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
clang++ is talking about using gcc 4.9 stuff, but if I do:
g++ --version
it outputs:
g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 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
This is where iostream is located on my machine:
/usr/share/doc/fp-docs/2.6.2/fcl/iostream
/usr/include/boost/tr1/tr1/iostream
/usr/include/c++/4.8/iostream

Seeing as how clang++ was keen on using g++ 4.9 files, I decided to install g++ 4.9
ubuntu does not have 4.9 as part of it's normal "sudo apt-get install g++". They are still on 4.8. (not sure what put the gcc 4.9 (but apparently not g++ 4.9) stuff on my system).
I found out that I could install g++ 4.9 by doing:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
After these commands were issued, clang++ was able to find <iostream>.

Try to install these packages,
sudo yum groupinstall "Development Tools"
sudo yum install libstdc++-static.x86_64 compat-libstdc++-33.x86_64
I have had this problem and it was solved installing these packages.

Related

How to build and link for specific GLIBC version

My ubuntu build environment by default uses g++ 9.4.0 with this ldd version:
ldd (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31
My run environment is a hadoop environment that must be using a much older GLIBC because it gives me errors like this when I try to run myApp there:
./myApp: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by ./myApp)
./myApp: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./myApp)
./myApp: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./myApp)
./myApp: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./myApp)
I'm looking to resolve these errors in whichever way is easiest, but since I'm unsure of how to upgrade the hadoop environment, I'm starting with seeing if I can instead build using a lower GLIBC that will be available on the run environment. I'm struggling to understand how to accomplish this. To start, I've tried to install g++4.8 on the build environment as follows:
sudo apt-get install gcc-4.8 g++-4.8 build-essential
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --list cc
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --list c++
sudo update-alternatives --set c++ /usr/bin/g++
g++ --version
gcc --version
ldd --version
I was able to get this to install using bionic repos, but the ldd output is still GLIBC 2.31:
Setting up gcc-4.8-base:amd64 (4.8.5-4ubuntu8) ...
Setting up cpp-4.8 (4.8.5-4ubuntu8) ...
Setting up libasan0:amd64 (4.8.5-4ubuntu8) ...
Setting up gcc (4:9.3.0-1ubuntu2) ...
Setting up g++ (4:9.3.0-1ubuntu2) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (12.8ubuntu1.1) ...
Setting up libgcc-4.8-dev:amd64 (4.8.5-4ubuntu8) ...
Setting up gcc-4.8 (4.8.5-4ubuntu8) ...
Setting up libstdc++-4.8-dev:amd64 (4.8.5-4ubuntu8) ...
Setting up g++-4.8 (4.8.5-4ubuntu8) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...
update-alternatives: using /usr/bin/gcc-4.8 to provide /usr/bin/gcc (gcc) in auto mode
update-alternatives: using /usr/bin/g++-4.8 to provide /usr/bin/g++ (g++) in auto mode
update-alternatives: warning: forcing reinstallation of alternative /usr/bin/gcc because link group cc is broken
/usr/bin/gcc
update-alternatives: warning: forcing reinstallation of alternative /usr/bin/g++ because link group c++ is broken
/usr/bin/g++
g++ (Ubuntu 4.8.5-4ubuntu8) 4.8.5
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.
gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
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.
ldd (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31
Copyright (C) 2020 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.
When I run the resulting myApp on the run environment again, I get the same errors I noted above.
Is there a step that I'm missing to either force a specific GLIBC version or to update my build environment to use a g++ that defaults to a lower GLIBC version? I haven't found a way to use g++ 9.4.0 with say GLIBC_2.15 but can someone share with me tips on how that could be done?

Lua 5.3 is installed, but I can't locate the correct lua.h

I am trying to install some luarocks packages but it seems that although lua5.3 is installed, the relevant headers are not
$ which lua
/usr/bin/lua
$ lua -v
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
/usr/include$ ls *lua*
lua5.1:
lauxlib.h luaconf.h lua.h lua.hpp lualib.h
luajit-2.1:
lauxlib.h luaconf.h lua.h lua.hpp luajit.h lualib.h
$ locate lua.h
/usr/include/luajit-2.1/lua.h
/usr/include/luajit-2.1/lua.hpp
/usr/share/doc/texlive-doc/latex/greek-fontenc/lgr2licr.lua.html
/usr/src/linux-headers-5.4.0-31-generic/include/config/scsi/dh/alua.h
/usr/src/linux-headers-5.4.0-40-generic/include/config/scsi/dh/alua.h
/usr/src/linux-headers-5.4.0-66-generic/include/config/scsi/dh/alua.h
/usr/src/linux-headers-5.4.0-70-generic/include/config/scsi/dh/alua.h
$ sudo luarocks install luacheck
Installing https://luarocks.org/luacheck-0.24.0-2.src.rock
Missing dependencies for luacheck 0.24.0-2:
luafilesystem >= 1.6.3 (not installed)
luacheck 0.24.0-2 depends on luafilesystem >= 1.6.3 (not installed)
Installing https://luarocks.org/luafilesystem-1.8.0-1.src.rock
gcc -O2 -fPIC -I/usr/include/lua5.3 -c src/lfs.c -o src/lfs.o
src/lfs.c:84:10: fatal error: lua.h: No such file or directory
84 | #include <lua.h>
| ^~~~~~~
compilation terminated.
Any help would be really appreciated.
sudo apt install liblua5.3-dev

How to remove gcc 7.3 from RHEL 7?

RHEL 7 comes with built-in gcc of version 4.8.
If I do
yum remove gcc
then it removes gcc 4.8. How can I remove gcc 7.3 from the system completely?
I have tried to find the solution for the above problem but most of the solution is for Ubuntu. Can someone help to figure out a solution for CentOS/RHEL?
Thanks.
Note:
which gcc
/usr/local/bin/gcc
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --disable-multilib --enable-languages=c,c++
Thread model: posix
gcc version 7.3.0 (GCC)
Try to give version number in package name to yum:
yum remove gcc-7.3.0

Compilation error for RISCV gcc when try to include -lcrypto

I am running openssl benchmarks on Ubuntu Linux. Initially, there was some problem with the missing library. Later I fixed it by installing the library with the installation command sudo apt-get install libssl-dev. When I compiled using gcc command gcc sha256t.c -o sha -lcrypto, it generates binary but when compiled using RISCV gcc command riscv64-unknown-elf-gcc sha256.S -o sha.riscv -lcrypto, it throws the following link error.
/home/user_name/fpga-zynq/rocket-chip/riscv-tools/riscv/lib/gcc/riscv64-unknown-elf/6.1.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status.
How to link the -lcrypto in this case.
You need a libcrypto compiled for the riscv64 architecture.
What you installed with sudo apt-get install libssl-dev is a libcrypto compiled for your host architecture (likely x86_64), it cannot be used for cross-compiling.
If you can't find a pre-built libcrypto for riscv64, you might have to compile it yourself, with that same riscv64 cross-compiler you're using.
Automating this is what yocto or buildroot is all about.

Building the FBX SDK on Linux

Trying to get one of the samples compiled on Ubuntu 12.04
I’m using
make -f Makefile-x64-static
However, I get the error
make: gcc4: Command not found
I tried switching from gcc4 to gcc in the makefile.
However, I get the compile errors
note: #pragma message: IMPORTANT NOTE: The FBX SDK API changed substantially. Please define FBXSDK_NEW_API in your project and fix compilation errors as instructed in fbxsdk_compatibility.h.
And the link error
/usr/bin/ld: cannot find -luuid
Any tips would be appreciated.
Pre-requisites
sudo apt-get install uuid-dev
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install libx11-dev
Makefile modifications required
Change gcc4 to gcc
CC = gcc
LD = gcc
add -lX11 to LIBS
LIBS = -lfbxsdk-$(LIBFBXVERSION)$(STATIC) -lm -lrt -luuid -lc -lstdc++ -lpthread -ldl -lglut_gcc34-amd64 -lGLEW_amd64 -lGLU -lGL -lXmu -lX11
add -DFBXSDK_NEW_API to C_FLAGS and CXX_FLAGS
CFLAGS = -m64 -DFBXSDK_NEW_API
CXXFLAGS = -m64 -DFBXSDK_NEW_API

Resources