How to I get crosstool-ng C++ compiler working

喜你入骨 提交于 2019-12-12 12:12:37

问题


I'm trying to get crosstool-ng working with both C and C++. Even though I've selected C++ while using menuconfig, it doesn't seem to get built. The gcc compiler works as expected but not g++

I'm not sure what I'm doing wrong so any help would be appreciated.

I followed the steps found here: Building embedded ARM systems with Crosstool-NG

$ arm-unknown-linux-gnueabi-cpp main.cpp -o test
arm-unknown-linux-gnueabi-cpp: main.cpp: C++ compiler not installed on this system

NOTE: there is no arm-unknown-linux-gnueabi-g++ found on in the bin directory. I've tried cross-tool version 1.16.0 and 1.15.3

arm-unknown-linux-gnueabi-cpp -v
Using built-in specs.
Target: arm-unknown-linux-gnueabi
Configured with: /opt/crossArm/.build/src/gcc-4.3.2/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-unknown-linux-gnueabi --prefix=/opt/crossArm/.build/arm-unknown-linux-gnueabi/buildtools --with-local-prefix=/home/jgarvin/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot --disable-libmudflap --with-sysroot=/home/jgarvin/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot --enable-shared --with-pkgversion='crosstool-NG 1.16.0' --with-float=soft --enable-__cxa_atexit --with-gmp=/opt/crossArm/.build/arm-unknown-linux-gnueabi/buildtools --with-mpfr=/opt/crossArm/.build/arm-unknown-linux-gnueabi/buildtools --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-nls --disable-multilib --enable-languages=c
Thread model: posix
gcc version 4.3.2 (crosstool-NG 1.16.0)

Code

#include<iostream>

using namespace std;

int main(){
   cout<<"Hello World"<<endl;
return 0;
}

In my build.log file I see C++ option turned on

[DEBUG]    CT_CC_SUPPORT_CXX=y

I also see it in the config.log:

configure:3030: $? = 0
configure:3019: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu

回答1:


From, http://briolidz.wordpress.com/2012/02/07/building-embedded-arm-systems-with-crosstool-ng/

Refine your configuration by running the menuconfig interface:

$ ./ct-ng menuconfig

In this step, navigate to the C Compiler menu. Then you can select C++ or de-select Java, Fortran, etc. Since crosstool-ng is just a bunch of scripts and patch files, it is very rare that a development build breaks things. You can always pull from the hg repository.

hg clone http://crosstool-ng.org/hg/crosstool-ng
cd crosstool-ng
./bootstrap
make
sudo make install

This will have the latest fixes. I have built arm cross compilers with C++ support many times using this method [including Canadian crosses for Mingw and i386 from an x86_64 host].

EDIT: I see that the wordpress link recommends a local install of ct-ng. The commands above do a full install, putting things in /usr/local. Also, it seems the OP did try to set menuconfig's C++ option. Try altering the sjlj value, use the latest version of ct-ng and install it. This produces an ARM Linux C++ cross-compiler on Ubuntu for me. The build.log output can be helpful in determining if ct-ng decided some configuration was impossible.

Finally, the mailing list crossgcc@sourceware.org doesn't require subscription afaik. The archives at http://sourceware.org/ml/crossgcc/ can be helpful. If you still have issues, I am sure someone on the mailing list will be able to help you.

EDIT: With the latest ct-ng installed try,

$ ct-ng arm-cortex_a15-linux-gnueabi #Alternate arm-yem-linux-gnueabi
$ ct-ng menuconfig # Tweak for your processor, gcc version, etc.
$ ct-ng build # Go have a coffee (or work on something else).

Sorry, your host compiler was made with Linaro. I was reading too much into your edit.




回答2:


I was having similar issue. It turns out that I was looking at the wrong bin directory under .build. The final version of the toolchain was installed under ~/x-tools instead...




回答3:


If you are still looking for an answer on compiling c++ on arm platform:

Install crosstool-ng:

tar xjf <ct-ng archive>
cd crosstool-ng-<numversion>
# reset of LD_LIBRARY_PATH is required to avoid issues with crosstool-ng
unset LD_LIBRARY_PATH
./configure prefix=<installDir>
#example ./configure prefix=/opt/cross-rpi
make
make install
#required to make sure you get the right on in case
export PATH=<installDir>/bin:$PATH
#check what version is on now.
which ct-ng

Now create and launch the configuration:

mkdir chain-build #the directory hosting the build files of your cross compil chain
cd chain-build
ct-ng menuconfig

Set options are relevant to the arm platform amongst other:

Paths and misc Options

  • Configure the maximum log level to see to WARN instead of INFO which totally clutters the logs and in my opinion makes them hard to use, way too much noise for the usual use case.

Target options Operating System

  • Target Architecture

    • arm
  • System

    • linux

Binary utilities - Select the last version of binutils

C compiler

  • GCC : Select Show linaro Versions then select the lastest linaro gcc (more stable than non linaro, from experience)

  • C++ : Check it

Now build your toolchain

ct-ng build
# once done check the content of the bin dir
ls <yourChainInstallDir>/x-tools/arm-unknown-linux-gnueabi/bin

You should get something like this:

of all to compile c++ code you should only need g++. To check if g++ (for arm) works ok type

arm-unknown-linux-gnueabi-g++ -v

You should get something similar to this:

Using built-in specs.
COLLECT_GCC=x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++
COLLECT_LTO_WRAPPER=/opt/cross1.19/x-tools/arm-unknown-linux-gnueabi/libexec/gcc/arm-        unknown-linux-gnueabi/4.8.2/lto-wrapper
Target: arm-unknown-linux-gnueabi
[...]
blahblah
[...]
gcc version 4.8.2 20130603 (prerelease) (crosstool-NG 1.19.0)

Once you get this message you should be ok.

The only other thing to watch out for is if you got all of the libraries needed to compile your code.

e.g. for instance on Raspberry-pi (using Raspbian), some of the libs have to be manually imported from /lib and /usr/lib (put then in your LD_LIBRARY_PATH).

Sometimes the includes for gcc or g++ are not copied in the include directory of the toolchain (when using crosstool-ng, got the issue a couple of times), so you need to get the includes from your /usr/include directory.



来源:https://stackoverflow.com/questions/12957977/how-to-i-get-crosstool-ng-c-compiler-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!