So I downloaded gcc using homebrew so that I could update gcc and g++ to 4.7.
So then I:
$ mkdir ~/bin
created ~/.bashrc with contents:
'export PATH=$HOME/bin:$PATH'
created ~/.bash_profile with contents:
'. $HOME/.bashrc'
and then:
$ ln -s /usr/local/bin/g++-4.7 ~/bin/g++
so now I run g++ -v and it's 4.7, YAY!
Now I go to update gcc and do:
$ ln -s /usr/local/bin/gcc-4.7 ~/bin/gcc
I get no errors but then when I run gcc -v i get:
gcc-4.7: error trying to exec '/usr/local/bin/i686-apple-darwin10-gcc-4.2.1': execvp: No such file or directory
So it seems to be looking for 4.2 for some reason? If I cd to ~/bin/gcc and do ./gcc -v it works fine. Also echo $PATH has the correct ~/bin path. I'm not sure why g++ worked and gcc didnt.
I had the same problem.
This is because bash has hashed the gcc in other folder.
run: hash gcc
Then everything should go smooth.
Related
This question already has an answer here:
Why doesn't my script work on FreeBSD, even though it seems to work on Linux? It's as if FreeBSD ignores "if"
(1 answer)
Closed last month.
Here is how I tried it:
git clone https://github.com/FlatAssembler/AECforWebAssembly.git
cd AECforWebAssembly
if command -v g++ &> /dev/null
then
g++ -std=c++11 -o aec AECforWebAssembly.cpp
else
clang++ -o aec AECforWebAssembly.cpp
fi
cd analogClock
../aec analogClock.aec
npx -p wabt wat2wasm analogClock.wat
node analogClock
However, I get the following message when I try that on WSL Ubuntu:
teo#DESKTOP-C29Q2SM:~/AECforWebAssembly$ if command -v g++ &> /dev/null
> then
> g++ -std=c++11 -o aec AECforWebAssembly.cpp
> else
> clang++ -o aec AECforWebAssembly.cpp
> fi
Command 'clang++' not found, but can be installed with:
sudo apt install clang
How is that possible? clang++ is not supposed to be executed.
You have misunderstood how command is used.
You need to replace
command -v g++ &> /dev/null
, in your code above, with
[ $(command -v g++ &> /dev/null ; echo $?) -eq 0 ]
On X86, I need to build a gcc cross compiler for arm64 with things as below:
binutils-2.26.1.tar.gz gcc-5.4.0.tar.gz glibc-2.23.tar.gz gmp-6.1.2.tar.bz2 mpc-1.1.0.tar.gz mpfr-4.0.1.tar.gz
I've put all of them into a directory named download.
After reading this link: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/, I wrote a bash script as below to build the gcc cross compiler:
#!/bin/bash
sudo rm -rf build sources /opt/aarch64-linux-gnu-5.4.0
mkdir build
cp -r download sources
cd sources
for f in *.tar*; do tar xf $f; done
cd gcc-5.4.0/
ln -s ../mpfr-4.0.1 mpfr
ln -s ../mpc-1.1.0 mpc
ln -s ../gmp-6.1.2 gmp
cd ../..
export PREFIX=/opt/aarch64-linux-gnu-5.4.0
#export PATH=$PREFIX/bin:$PATH
export SYSROOT=$PREFIX/sysroot
export TARGET=aarch64-linux-gnu
cd build
mkdir binutils && cd binutils
../../sources/binutils-2.26.1/configure --prefix=/$PREFIX --target=$TARGET
make -j32
make install
cd ..
cd /home/me/projet/kernel/linux-4.1
make ARCH=arm64 INSTALL_HDR_PATH=$PREFIX/aarch64-linux-gnu/include headers_install
cd -
mkdir gcc && cd gcc
../../sources/gcc-5.4.0/configure --prefix=$PREFIX --target=$TARGET --enable-languages=c,c++ --without-headers
make -j32 all-gcc
make install-gcc
cd ..
mkdir -p glibc && cd glibc
../../sources/glibc-2.23/configure --prefix= --build=$MACHTYPE --host=$TARGET --target=$TARGET --with-headers=$PREFIX/aarch64-linux-gnu/include libc_cv_forced_unwind=yes
make prefix=$PREFIX/aarch64-linux-gnu install-bootstrap-headers=yes install-headers
make -j32 csu/subdir_lib
install csu/crt1.o csu/crti.o csu/crtn.o $PREFIX/aarch64-linux-gnu/lib
/opt/aarch64-linux-gnu-5.4.0/bin/aarch64-linux-gnu-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $PREFIX/aarch64-linux-gnu/lib/libc.so
touch $PREFIX/aarch64-linux-gnu/include/gnu/stubs.h
cd ..
cd gcc
make -j32 all-target-libgcc
make install-target-libgcc
cd ..
cd glibc
make -j32
make prefix=$PREFIX/aarch64-linux-gnu install
cd ..
cd gcc
make -j32
make install
cd ..
However, when I executed this bash script, I got two errors:
cc1: error: no include path in which to search for stdc-predef.h
In file included from ../../../../sources/gcc-5.4.0/libgcc/gthr.h:148:0,
from ../../../../sources/gcc-5.4.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
I would like to use library fgsl, that depends on gsl. I have problem indicating where gsl is installed while configuring fgsl. I want to use the static version of these libraries. I can not use gsl library from Linux packages, these versions are not recent enough.
First I download, configure, compile and install gsl locally, i.e. using the --prefix option. (Instructions are presented below)
Then I download fgsl, configure it. This last operation fails because I do not succeed indicating where is gsl. I have tried to use gsl_LIBS unsuccessfully.
wget http://ftp.igh.cnrs.fr/pub/gnu/gsl/gsl-2.3.tar.gz -O gsl.tar.gz
mkdir -p gsl_build && cd gsl_build
tar -xzf ../gsl.tar.gz --strip 1
autoreconf -fi
./configure CFLAGS="-Wall" --prefix `pwd`/../gsl
make
make install
cd ..
rm -rf gsl_build
Here are the commands I run to install fgsl
wget https://github.com/reinh-bader/fgsl/archive/v1.2.0.tar.gz -O fgsl.tar.gz
mkdir -p fgsl_build
cd fgsl_build
tar -xzf ../fgsl.tar.gz --strip 1
autoreconf -fi
export gsl_LIBS=`pwd`/../gsl/lib
./configure CFLAGS="-Wall" FCFLAGS="-Wall" --prefix `pwd`/../fgsl --libdir=`pwd`/../gsl/lib --includedir=`pwd`/../gsl/include
make
make check
make install
cd ..
rm -rf fgsl_build
I try to do this for the open source project AcousticBEM. Here is the log presenting the problem.
Well, here are my updated scripts to install gsl and fgsl locally. I have used PKG_CONFIG_PATH to tell fgsl where gsl is installed. I end up with a directory named gsl containing gsl libraries and fgsl libraries.
First a shell script to install gsl
export gsl_INSTALL_DIR=`pwd`/gsl
[ -f ./gsl.tar.gz ] && echo "No need to download gsl" || wget http://ftp.igh.cnrs.fr/pub/gnu/gsl/gsl-2.3.tar.gz -O gsl.tar.gz
mkdir -p gsl_build
cd gsl_build
tar -xzf ../gsl.tar.gz --strip 1
autoreconf -fi
./configure CFLAGS="-Wall" --prefix=${gsl_INSTALL_DIR}
make
make install
cd ..
rm -rf gsl_build
Second, a script to install fgsl locally using the newly install gsl
export PKG_CONFIG_PATH=`pwd`/gsl/lib/pkgconfig
export gsl_LIBS=`pwd`/gsl
[ -f ./fgsl.tar.gz ] && echo "No need to download fgsl" || wget https://github.com/reinh-bader/fgsl/archive/v1.2.0.tar.gz -O fgsl.tar.gz
mkdir -p fgsl_build
cd fgsl_build
tar -xzf ../fgsl.tar.gz --strip 1
autoreconf -fi
./configure CFLAGS="-Wall" FCFLAGS="-Wall" --prefix=${gsl_LIBS}
make
make check
make install
cd ..
rm -rf fgsl_build
libtool won't install on my mac via Homebrew nor MacPorts (needed for RVM).
This is the verbose output where it hangs forever, running OS X 10.9 & Xcode 4.3
libtool: link: ( cd "libltdl/.libs" && rm -f "dlopen.la" && ln -s "../dlopen.la" "dlopen.la" )
/bin/sh ./libtool --tag=CC --mode=link cc -g -O2 -no-undefined -version-info 10:0:3 -dlpreopen libltdl/dlopen.la -o libltdl/libltdl.la -rpath /usr/local/Cellar/libtool/2.4.2/lib libltdl/loaders/libltdl_libltdl_la-preopen.lo libltdl/libltdl_libltdl_la-lt__alloc.lo libltdl/libltdl_libltdl_la-lt_dlloader.lo libltdl/libltdl_libltdl_la-lt_error.lo libltdl/libltdl_libltdl_la-ltdl.lo libltdl/libltdl_libltdl_la-slist.lo libltdl/argz.lo
libtool: link: rm -f libltdl/.libs/libltdl.nm libltdl/.libs/libltdl.nmS libltdl/.libs/libltdl.nmT
libtool: link: (cd libltdl/.libs && cc -g -O2 -c -fno-builtin -fno-rtti -fno-exceptions -fno-common -DPIC "libltdlS.c")
brew: superenv removed: -g -O2
libtool: link: rm -f "libltdl/.libs/libltdlS.c" "libltdl/.libs/libltdl.nm" "libltdl/.libs/libltdl.nmS" "libltdl/.libs/libltdl.nmT"
Any ideas?
I has the same issue, did a bit of tracing and found that is was actually stuck waiting for output to be grepped from the "lipo" command.
Looked around a bit and found the following solution: replace
/usr/bin/lipo
with the one under
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
and the compilation will work. You need the development environment to be installed.
MrWHO
Rather than replace your system files, most configure scripts will take accept taking lipo as a env variable:
export LIPO=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo
./configure
make
None of the other solutions worked for me, and, admittedly, my error message wasn't identical but did contain a rm -rf, so to whomever this might help:
What got rid of this error for me was adding this line immediately before the call to make (well gmake really in my case):
ENV.deparallelize
What led me to this was noticing that there was another line in the log output with exactly the same content, but which succeeded, so I reckoned this might be a timing/ordering issue, so ENV.deparallelize was the first thing to try.
P.S. If anyone could shed light onto why parallelization inside make might be causing this, I'd appreciate that — non-parallel make is so much slower!
UPDATE: adding env :std solved the issue for me without requiring ENV.deparallelize; thanks to ilovezfs on #machomebrew for the hint!
I build gcc 4.6.1 and when I run ldconfig it comes back with this result:
ldconfig: /usr/local/mpc/lib/libmpc.so.2 is not a symbolic link
ldconfig: /usr/local/gmp/lib/libgmp.so.3 is not a symbolic link
ldconfig: /usr/local/mpfr/lib/libmpfr.so.1 is not a symbolic link
Here is how I built gcc using the libraries:
tar jxf gmp-4.3.2.tar.bz2
cd gmp-4.3.2/
./configure --prefix=/usr/local/gmp
make
make install
cd ..
tar jxf mpfr-2.4.2.tar.bz2
cd mpfr-2.4.2/
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make
make install
cd ..
tar xzf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --prefix=/usr/local/mpc --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp
make
make install
cd ..
tar jxf gcc-4.6.1.tar.bz2
cd gcc-4.6.1
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking -disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr/ --with-mpc=/usr/local/mpc/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
make
make install
cp gcc.4.6.1.conf /etc/ld.so.conf.d/gcc.4.6.1.conf
ldconfig
mv /usr/bin/gcc /usr/bin/gcc_old
mv /usr/bin/g++ /usr/bin/g++_old
ln -s -f /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s -f /usr/local/gcc/bin/g++ /usr/bin/g++
cp /usr/local/gcc/lib64/libstdc++.so.6.0.16 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.16 /usr/lib64/libstdc++.so.6
Please say I don't need to rebuild gcc! Is this symbolic link problem something that can really affect a program? Or will it not make any difference, it does pop up every now and again, for instance when I was yum install certain things as well. Thanks in advance.
I fixed this problem by installing gmp, mpc, and mpfr with the ./contrib/download_prerequisites command, which downloads the required files and sets up symbolic links during the install process.
My whole build was:
tar -xzvf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.6.2/configure --prefix=/opt/gcc-4.6.2
make
make install
ldconfig
mv /usr/bin/gcc /usr/bin/gcc_old
mv /usr/bin/g++ /usr/bin/g++_old
ln -s -f /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s -f /usr/local/gcc/bin/g++ /usr/bin/g++
cp /usr/local/gcc/lib64/libstdc++.so.6.0.16 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.16 /usr/lib64/libstdc++.so.6
export CC=gcc
export CXX=g++
I don't know how to fully link the CC and CXX variables to the new gcc and g++, but it works!