How to change arm version in arm-linux-gnueabi-gcc for cross compile - c++

I want to cross-compile in eclipse for board armv7l.
I got the armv7l via, uname -i.
I installed ARM cross compiler toolchain, using below commands.
$ sudo apt-get install emdebian-archive-keyring
$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross
$ sudo apt-get install binutils-arm-linux-gnueabi
$ sudo apt-get install gcc-arm-linux-gnueabi
$ sudo apt-get install g++-arm-linux-gnueabi
$ sudo apt-get install u-boot-tools
$ sudo apt-get install libncurses5-dev
I think I have to give an option for my target board version.
First time I tried to put arm-linux-gnueabi-g++ in C/C++ Build->settings->GCC C++ Compiler and GCC C++ Linker.(eclipse project properties)
Next I put -march=armv7 in Miscellaneous
But it was not working. I checked the executable file with readelf -A
and it shows this
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Tag_CPU_arch_profile: Application
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv3-D16
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_HardFP_use: SP and DP
Tag_CPU_unaligned_access: v6
Tag_DIV_use: Not allowed
What option I have to put for my target board ?

Related

installation error: 'Unable to locate package g++-4.8'

I am trying to install gcc and g++ version 4.8 to run a specific software in Ubuntu 22.04.1
when I perform
sudo apt-get install g++-4.8
it says
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package g++-4.8
E: Couldn't find any package by glob 'g++-4.8'
E: Couldn't find any package by regex 'g++-4.8'
and When I perform
sudo apt-get install gcc-4.8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'gcc-4.8-hppa64' for regex 'gcc-4.8'
The following packages were automatically installed and are no longer required:
chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi i965-va-driver intel-media-va-driver libaacs0 libaom3 libass9 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2
libbs2b0 libchromaprint1 libcodec2-1.0 libdav1d5 libflashrom1 libflite1 libftdi1-2 libgme0 libgsm1 libgstreamer-plugins-bad1.0-0 libigdgmm12 liblilv-0-0 libmfx1 libmysofa1
libnorm1 libopenmpt0 libpgm-5.3-0 libpostproc55 librabbitmq4 librubberband2 libserd-0-0 libshine3 libsnappy1v5 libsord-0-0 libsratom-0-0 libsrt1.4-gnutls libssh-gcrypt-4
libswresample3 libswscale5 libudfread0 libva-drm2 libva-wayland2 libva-x11-2 libva2 libvdpau1 libvidstab1.1 libx265-199 libxvidcore4 libzimg2 libzmq5 libzvbi-common libzvbi0
mesa-va-drivers mesa-vdpau-drivers pocketsphinx-en-us va-driver-all vdpau-driver-all
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
What could be done?
You could possibly recompile gcc 4.8.5 with the following script. However there is a lot that can go wrong depending on the machine that you are compiling it since the compiler itself depends on a large set of utilities - called the toolchain and they are tightly coupled with the machine's own system libraries, in particular the C standard library.
sudo dpkg --add-architecture i386
sudo apt update
sudo apt upgrade
sudo apt-get install gcc-multilib libstdc++6:i386
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2 --no-check-certificate
tar xf gcc-4.8.5.tar.bz2
cd gcc-4.8.5
./contrib/download_prerequisites
cd ..
sed -i -e 's/__attribute__/\/\/__attribute__/g' gcc-4.8.5/gcc/cp/cfns.h
sed -i 's/struct ucontext/ucontext_t/g' gcc-4.8.5/libgcc/config/i386/linux-unwind.h
mkdir xgcc-4.8.5
pushd xgcc-4.8.5
$PWD/../gcc-4.8.5/configure --enable-languages=c,c++ --prefix=/usr --enable-shared --enable-plugin --program-suffix=-4.8.5
make MAKEINFO="makeinfo --force" -j
sudo make install -j

Clang does not find <future> header when using libc++ [duplicate]

I am wondering what is the right/easy way to install a binary libc++ on Ubuntu, in my case Trusty aka 14.04?
On the LLVM web site there are apt packages http://apt.llvm.org/ and I have used these to install 3.9. However these packages don't seem to include libc++. I install the libc++-dev package but that seems to be a really old version. There are also binaries that can be downloaded http://llvm.org/releases/download.html#3.9.0. These do seem to contain libc++ but I'm not sure if I can just copy bits of this into places like /usr/include/c++/v1, in fact I'm not really sure what bits I would need to copy. I am aware I can use libc++ from an alternate location as documented here http://libcxx.llvm.org/docs/UsingLibcxx.html which I have tried. However I can't modify the build system of the large code base I work on to do this.
So is three any reason the apt packages don't include libc++ and any pointers to installing a binary would be gratefully recieved.
How to build libc++ on Ubuntu 16.04
I had a similar issue as you do. While testing clang with libstdc++ worked fine with C++11 and C++14 there still might be licensing issues with libstdc++. So I ended up installing Clang toolchain from their repos and compiling libc++ on Ubuntu 16.04.
Disclaimer: This post is summary of long search on how to build the libc++ on Ubuntu Linux. Many of the posts I found in 2017 were either outdated or described a partial solution on other systems e.g. CentOS. Links to these posts are:
Hacking with Clang llvm abi and llvm libc
Building Clang and libc++ on Ubuntu Linux
How to Build libcxx and libcxxabi by clang on CentOS 7
Here are the steps to build LLVM + Clang + libc++ from the 4.0 release branch:
Install the key of LLVM Repositories
# apt-get update && apt-get dist-upgrade -y && apt-get install -y vim curl && \
curl -q https://apt.llvm.org/llvm-snapshot.gpg.key |apt-key add -
Create a new new APT Repository File (you can also exclude 2 lines referring to v3.9 repos)
# cat > /etc/apt/sources.list.d/llvm-repos.list <<EOF
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main
EOF
Install Clang and all Packages needed to build libc++ from LLVM repos
# apt-get update && apt-get install -y clang-4.0 clang-4.0-doc \
libclang-common-4.0-dev libclang-4.0-dev libclang1-4.0 libclang1-4.0-dbg \
libllvm4.0 libllvm4.0-dbg lldb-4.0 llvm-4.0 llvm-4.0-dev llvm-4.0-runtime \
clang-format-4.0 python-clang-4.0 liblldb-4.0-dev lld-4.0 libfuzzer-4.0-dev \
subversion cmake
Create an alternative for C++ compiler and linker. This is not a must, but lets you switch compilers or linkers if needed. Also some build files needed cc or c++ or clang++ as far as I remember. Keep in mind, that we switch to LLD linker as default:
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-4.0 100 \
&& update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-4.0 100 \
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-4.0 100 \
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-4.0 100 \
&& update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld-4.0 10 \
&& update-alternatives --install /usr/bin/ld ld /usr/bin/ld.gold 20 \
&& update-alternatives --install /usr/bin/ld ld /usr/bin/ld.bfd 30 \
&& ld --version && echo 3 | update-alternatives --config ld && ld --version
Checkout sources of libc++ and libc++abi:
$ cd /tmp
$ svn co http://llvm.org/svn/llvm-project/libcxx/branches/release_40/ libcxx
$ svn co http://llvm.org/svn/llvm-project/libcxxabi/branches/release_40/ libcxxabi
$ mkdir -p libcxx/build libcxxabi/build
To run libc++ on Linux one needs ABI compatibility to the standard library, e.g. libstdc++. This is where libc++abi comes into game. The only problem is that it needs libc++ to be on the system for which it is build. Thus libc++ is built in 2 steps. First: without any ABI compatibility. But it will be used for bootstrapping of ABI lib and than the second step is to recompile libc++ with the proper ABI present on system:
Bootstraping => build libc++ without proper ABI:
cd /tmp/libcxx/build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_CONFIG_PATH=/usr/bin/llvm-config-4.0\
-DCMAKE_INSTALL_PREFIX=/usr .. \
&& make install
Building libc++abi with libstdc++ compatible ABI:
cd /tmp/libcxxabi/build
CPP_INCLUDE_PATHS=echo | c++ -Wp,-v -x c++ - -fsyntax-only 2>&1 \
|grep ' /usr'|tr '\n' ' '|tr -s ' ' |tr ' ' ';'
CPP_INCLUDE_PATHS="/usr/include/c++/v1/;$CPP_INCLUDE_PATHS"
cmake -G "Unix Makefiles" -DLIBCXX_CXX_ABI=libstdc++ \
-DLIBCXX_LIBSUPCXX_INCLUDE_PATHS="$CPP_INCLUDE_PATHS" \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
-DLLVM_CONFIG_PATH=/usr/bin/llvm-config-4.0 \
-DLIBCXXABI_LIBCXX_INCLUDES=../../libcxx/include ..
make install
Rebuild libc++ with proper ABI lib deployed on system:
cd /tmp/libcxx/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
-DLIBCXX_CXX_ABI=libcxxabi -DLLVM_CONFIG_PATH=/usr/bin/llvm-config-4.0\
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=../../libcxxabi/include .. \
&& make install
Create a test file to check whether everything works fine. IMO you should also test cerr stream, as previously it was not supported with the libc++abi and there were some segfaults. Please refer to this question.
create a test.cpp file:
#include <iostream>
int main()
{
using namespace std;
cout << "[OK] Hello world to cout!" << endl;
cerr << "[OK] Hello world to cerr!" << endl;
clog << "[OK] Hello world to clog!" << endl;
return 0;
}
And compile it and run it using this command line:
clang++ -std=c++11 -stdlib=libc++ -lc++abi test.cpp && ./a.out
Reason there is no package
I found libc++ packages for Ubuntu but they are a bit behind recent version: https://packages.ubuntu.com/xenial/libc++-dev
Why they are not current, I can't answer, but my guess is that LLVM+Clang can work with mostly any Standard Library, whereas libc++ as you see must be linked to particular runtime ABI and might heavily depend on available C runtime library. I agree there should be a package which covers 90% of the cases. May be this is just the lack of resources. Searching the mailing archive did not bring up anything special.
sudo apt-get update
sudo apt-get install libc++-dev
The accepted answer gave me some errors (it is Nov 2021 currently). Also, sudo apt install libc++-dev libc++abi-dev did not provide the latest libc++. Here is an alternate solution.
Use the LLVM apt package maintainer's script:
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
This automatically sets up the apt repositories and gives you the latest LLVM toolchain.
clang-13 --version
Since you now have the latest LLVM packages available from http://apt.llvm.org you can install the latest libc++. First determine the latest version:
apt search libc++ | grep libc++
Then:
sudo apt install libc++-13-dev libc++abi-13-dev
Optionally, you can use update-alternatives to make your system use clang-13 instead of the default. There is a gist for that:
wget https://gist.githubusercontent.com/junkdog/70231d6953592cd6f27def59fe19e50d/raw/update-alternatives-clang.sh
chmod +x update-alternatives-clang.sh
sudo ./update-alternatives-clang.sh 13 1000
Now:
clang --version
Debian clang version 13.0.1-++20211110062941+9dc7d6d5e326-1~exp1~20211110183517.26
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
The easiest way to get a working libc++ is to install the entire 3.9.0 toolchain under /usr/local. This will allow /usr/local/bin/clang++ to find the headers correctly and also allow the linker to find /usr/local/lib/libc++.so.
check my shell-script automation version:
https://github.com/sailfish009/llvm_all
$ sudo apt-get install libffi-dev libedit-dev swig git
$ git clone https://github.com/sailfish009/llvm_all
$ git clone https://github.com/llvm/llvm-project
$ cd llvm_all
$ cp *.sh ../llvm-project/
$ cd ../llvm-project/
$ ./set.sh
$ ./install.sh
$ clang++ --version
clang version 11.0.0 (https://github.com/llvm/llvm-project 032251e34d17c1cbf21e7571514bb775ed5cdf30)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Just build it yourself, as explained here. I added -D CMAKE_CXX_COMPILER=clang++ -D CMAKE_C_COMPILER=clang to use clang as the compiler:
$ git clone https://github.com/llvm/llvm-project.git
$ cd llvm-project
$ mkdir build
$ cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -D CMAKE_CXX_COMPILER=clang++ -D CMAKE_C_COMPILER=clang # Configure for clang++
$ ninja -C build cxx cxxabi unwind # Build
$ ninja -C build check-cxx check-cxxabi check-unwind # Test
$ ninja -C build install-cxx install-cxxabi install-unwind # Install

Update g++ but still old version

I installed g++ using those commands line:
sudo add-apt-repository ppa:jonathonf/gcc-7.1
sudo apt-get update
Then
sudo apt-get install gcc-7 g++-7
When it was done I tried g++ -v but still shows me the old version
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
Am I not upgrading it correctly?
Edit
:~$ dpkg -L g++-7
/.
/usr
/usr/lib
/usr/lib/gcc
/usr/lib/gcc/x86_64-linux-gnu
/usr/lib/gcc/x86_64-linux-gnu/7
/usr/lib/gcc/x86_64-linux-gnu/7/cc1plus
/usr/share
/usr/share/doc
/usr/share/doc/gcc-7-base
/usr/share/doc/gcc-7-base/C++
/usr/share/doc/gcc-7-base/C++/README.C++
/usr/share/doc/gcc-7-base/C++/changelog.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/x86_64-linux-gnu-g++-7.1.gz
/usr/bin
/usr/bin/x86_64-linux-gnu-g++-7
/usr/share/doc/g++-7
/usr/share/man/man1/g++-7.1.gz
/usr/bin/g++-7
:~$ which g++
/usr/bin/g++
Installing a newer (or older) version of GCC than the Ubuntu default version via the package manager
does not delete the default version. You get both. You can install as many
versions as you like. gcc/g++ will continue
to run the default version. If you have installed GCC 7, then you run
the new compilers with gcc-7 or g++-7. For most build systems, it is sufficient to set the environment variables CC=gcc-7 CXX=g++-7 before starting the build.
I installed the gcc-7 using the directions given in Ubuntu Forum, rebooted the system (to make sure all environment variables are loaded) and to compile with C++ 17, type the following on the shell :
g++-7 -std=c++17 program_name.cpp -o program.out
Hope this helps.

Install g++ 4.9 on Mint 17.2

I'm trying to install g++ 4.9 or greater in order to build mapbox on Android. The instructions state I need g++ 4.9 or greater. I found the following instructions, but they don't work.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
The last command says:
~ $ sudo apt-get install g++-4.9
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package g++-4.9 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'g++-4.9' has no installation candidate
I also tried from Synaptic Package Manager and got the following:
g++:
Depends: cpp (>=4:4.9-1ubuntu7) but 4:4.8.2-1ubuntu6 is to be installed
Depends: gcc (>=4:4.9-1ubuntu7) but 4:4.8.2-1ubuntu6 is to be installed
Depends: g++-4.9 (>=4.9) but it is not installable
Depends: gcc-4.9 (>=4.9) but it is not installable
How can I get g++ 4.9 on my computer?
Thanks.
Here is how to install g++-4.9 on Linux Mint 17.2 Rafaela
Go to menu -> Administration -> Software sources
Click on Additional repositories and then Getdeb
Click on Edit URL...
Replace deb http://archive.getdeb.net/ubuntu trusty-getdeb apps
by
deb http://archive.getdeb.net/ubuntu wily-getdeb apps
and click on Update the cache
At this point you can go with
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9
You can invoke your g++ like this:
g++-4.9
Now you have g++ 4.9.3 installed
And as an add, you can have the latest g++-5 (g++ 5.2.1) compiler
sudo apt-get install g++-5

Where can I find the real arm-none-linux-gnueabi?

Some time before I installed arm-none-linux-gnueabi-gcc compiler collection and compiled embedded applications for IGEP board. I have many Eclipse projects which has double build configurations (one for UBUNTU based desktop, the other for ARM based IGEPv2 board).
Now, I formatted my drive (I use Ubuntu 12.04) , I rescued my projects and what I see? "arm-none-linux-gnueabi-gcc" is not available? I can download it nowhere.. Instead, all the links go to another download by "Mentor Graphics", which is named "arm-none-eabi-gcc". I do not know the difference between. I setup this package and correct all my .../CodeSourcery/... type of paths to /MentorGraphics/..., but when I compile I have the following error:
/home/fercis/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/arm-none-eabi/include/termios.h:4:25:
fatal error: sys/termios.h: No such file or directory
Then I looked at the include file of the arm compiler collection under "/home/fercis/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/arm-none-eabi/include" and what I see was a termios.h under the .../include directory, which only includes .../include/sys/termios.h
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/termios.h>
#ifdef __cplusplus
}
#endif
And, There is no "/sys/termios.h". Something must be terribly wrong! Help please?
You can build your own toolchain for the IGEPv2 following these steps:
Install dependencies:
$ sudo apt-get install diffstat
$ sudo apt-get install texi2html
$ sudo apt-get install texinfo
$ sudo apt-get install gawk
$ sudo apt-get install chrpath
$ sudo apt-get install gnupg
$ sudo apt-get install libcurl3
$ sudo apt-get install libcurl3-gnutls
$ sudo apt-get install python-pycurl
Clone IGEPv2 repo:
$ git clone -b denzil git://git.isee.biz/pub/scm/poky.git
Download isee layer:
$ cd poky
$ git clone -b denzil git://git.isee.biz/pub/scm/meta-isee.git
Setup bitbake environment:
$ source oe-init-build-env
Add isee layer on conf/bblayers.conf file:
BBLAYERS ?= " \
/path/to/poky/meta \
/path/to/poky/meta-yocto \
/path/to/poky/meta-isee \
"
Change MACHINE on conf/local.conf file:
MACHINE ??= "igep00x0"
This command generates toolchain:
$ bitbake meta-toolchain-sdk
This is a good time to take a long coffee...
At the end of process, SDK will be available here:
build/tmp/deploy/sdk/igep-sdk-yocto-toolchain-1.2.1-2.tar.bz2
Install SDK in your host machine:
$ tar xvfz igep-sdk-yocto-toolchain-1.2.1-2.tar.bz2 -C /
Enjoy it! :)