Configure which gcc is called by shell script - linux

I've been struggling with this issue for several weeks now, working it off and on. I've got Ubuntu running on Windows. I also installed OpenFOAM to analyze CFD simulations. My issue is the default the gcc called at the command prompt is the OpenFOAM one.
$ gcc --version
gcc (OpenFOAM) 6.3.0
I needed updated libraries installed for something else I'm working on. I managed to get all the libraries installed, but linux is still looking to the OpenFOAM version of gcc (which doesn't see the libraries) when I run the program at the command prompt. I am calling a shell scrip that in turns calls other programs, so I cannot determine a way to directly call out the full path to the desired gcc version.
I've worked out that the bash gcc command is actually linked to three versions of gcc:
$ type -a gcc
gcc is /opt/OpenFOAM/OpenFOAM-v2012/ThirdParty/platforms/linux64/gcc-6.3.0/bin/gcc
gcc is /usr/bin/gcc
gcc is /bin/gcc
This leads me to believe that the shell scrip is going to the first one and ignoring the next two. How do I get it to go to the second?
i.e. so terminal would return
gcc is /usr/bin/gcc
gcc is /bin/gcc
gcc is /opt/OpenFOAM/OpenFOAM-v2012/ThirdParty/platforms/linux64/gcc-6.3.0/bin/gcc
This should yield the correct version of gcc being called and the installed libraries I need to be referenced at runtime.
$ which gcc
/opt/OpenFOAM/OpenFOAM-v2012/ThirdParty/platforms/linux64/gcc-6.3.0/bin/gcc
I was expecting this to return /usr/bin/gcc instead.
I tried appending the /bin/gcc/ to the front of the path variable:
$ export PATH = /usr/bin/:$PATH
without success. (edited for syntax)
I also researched installing multiple versions of gcc on Ubuntu and worked out there is a command that should permit me to do what I'm trying to, but it doesn't work:
$ sudo update-alternatives --config gcc
update-alternatives: error: no alternatives for gcc
I was expecting to be able to select which version of gcc was called.

Thanks for rici's input:
$ export PATH=/usr/bin:$PATH
prepended '/usr/bin' to the path variable before all the OpenFOAM stuff.
$ type -a $PATH
returned
gcc is /usr/bin/gcc
gcc is /opt/OpenFOAM/OpenFOAM-v2012/ThirdParty/platforms/linux64/gcc-6.3.0/bin/gcc
gcc is /usr/bin/gcc
gcc is /bin/gcc
This should have resolved my issue except for some reason it's still looking for another library in the OpenFOAM directories. As for the original question, the matter is resolved.

Related

cannot revise gcc version even after installing the new and deleting the old one

I work on CentOS 5.5 and my computer used gcc-4.1.2 until now, and under /usr/lib/gcc/x86_64-redhat-linux/ there were 2 indexes: 4.1.1 and 4.1.2. For using some softwares I must update the gcc.
But after I installed gcc-4.7.0 from the downloaded gcc-4.7.0.tar.gz (I did not use yum because when I tried it all servers told me that I had the latest version which was certainly not true, and perhaps this was also caused by the problem I now face with), the /usr/lib/gcc/x86_64-redhat-linux/4.7.0/ was created just like the 4.1.1 and 4.1.2 index, so under /usr/lib/gcc/x86_64-redhat-linux/ there were 3 indexes: 4.1.1, 4.1.2 and 4.7.0. And under /usr/lib/gcc/x86_64-redhat-linux/4.7.0/ there were 6 indexes:
bin include lib lib64 libexex share
It looked like that 4.7.0 was successfully installed but when I ran
gcc --version
the result was still
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
Copyright (C) 2006 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.
I also ran
update-alternatives --install /usr/bin/gcc gcc /usr/lib/gcc/x86_64-redhat-linux/4.7.0 40
to raise the priority of 4.7.0, and when I ran
update-alternatives --config gcc
it said
There is 1 program that provides 'gcc'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/gcc/x86_64-redhat-linux/4.7.0
Enter to keep the current selection[+], or type selection number:
And I printed 1, all it looked like that 4.7.0 was selected as the default gcc, but when I ran gcc --version, the result was not changed! Still 4.1.2.
After that I even removed all 4.1.2 gcc and its related programs by rpm -e and deleted the index, but the result of gcc --version became
-bash: gcc: command not found.
It didn’t change when I reinstalled the 4.7.0.
After all, when I looked for the links of /usr/bin/gcc/ I found
/usr/bin/gcc -> /etc/alternatives/gcc
and link of /etc/alternatives/gcc was
/etc/alternatives/gcc -> /usr/lib/gcc/x86_64-redhat-linux/4.7.0
this should be the result of my running the update-alternatives line, so it has worked. It did make the link to 4.7.0. So why didn’t this link call 4.7.0 in the end? I can’t find out.
I even made the direct link to 4.7.0 then:
ln -s /usr/lib/gcc/x86_64-redhat-linux/4.7.0 /usr/bin/gcc
however this still didn’t work.
I am very confused with it. I will be grateful for your help. Thank you very much!
p.s. Thank Basile Starynkevitch very much for noticing me to make these explanations:
I have /usr/bin/ in my PATH, so this should be OK.
I am teached that /usr/bin/gcc/ should be linked to an executable but not index, so the link to 4.7.0 is wrong. But could anyone tell me which executable to link to, or which executable is /usr/bin/ linked to in a common computer? This may very likely lead to the solution to the problem.
I cannot run configure one more time because configure itself requires gcc but now it is not found. So I'm afraid the problem cannot be fixed by that.
Be aware of the PATH variable. You could have some $HOME/bin/ in it.
Restore your system's gcc (so undo all the mess you have done). Then run which gcc and gcc -v to understand what is it exactly.
If you compile GCC from its source code (as distributed by the FSF), choose a recent version, e.g. GCC 8 in fall 2018.
Read carefully about installing GCC. Compile it outside of its source code. Be aware of the many configure options. I suggest to consider configuring it with some --program-suffix option (such as --program-suffix=-8) and then adding symlinks (e.g. $HOME/bin/gcc -> /usr/local/bin/gcc-8) appropriately.
ln -s /usr/lib/gcc/x86_64-redhat-linux/4.7.0 /usr/bin/gcc
it is wrong. Since /usr/lib/gcc/x86_64-redhat-linux/4.7.0/ is some internal directory, and /usr/bin/gcc has to be an executable.
You probably don't need to run update-alternatives, but you do need to add (cleverly) something in a directory mentioned in your PATH
See also this answer to a similar question.
after edits in the question
You need first to clean up the mess you did under /usr/ (in particular in /usr/bin/ which you should never change without your package system). Remove all the things you added under /usr/bin/ and /usr/lib/. Then re-install forcibly and explicitly appropriate system gcc packages (using yum or some other package manager).
I have /usr/bin/ in my PATH, so this should be OK.
Probably not. My recommendation is to have $HOME/bin/ and /usr/local/bin/ early in your PATH (so before /usr/bin/; you might need to edit ~/.bashrc to change your PATH setting) and to add your new gcc, as something like gcc-8 (if you compile GCC 8 from its source code), there. If you want a system wide installation, have some /usr/local/bin/gcc-8 program. If you want a personal installation, have some $HOME/bin/gcc-8 program (both could be absolute symlinks to somewhere else).

Remove all previous version MPI and reinstall correctly it

First of all: I'm on linux mint 17.3 x64
What I've done so far:
Guide to install Open MPI 1.8
Guide to install MPI
Attemp to remove MPI executing: sudo apt-get install libcr-dev mpich2 mpich2-doc (Actually the should be not installed)
What I can see from terminal:
output of: echo $PATH
/path/to/mpj//bin:/home/timmy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/timmy/.openmpi/bin
(I immagine that I've to remove /path/to/mpj/ (not exists) and /home/timmy/.openmpi/bin (I want to remove previous version of ompi))
output of: echo $LD_LIBRARY_PATH
(nothing)
Really, doesn't appear anything!
output of mpirun
--------------------------------------------------------------------------
mpirun could not find anything to do.
It is possible that you forgot to specify how many processes to run
via the "-np" argument.
--------------------------------------------------------------------------
Why I want to remove Open MPI and reinstall it
I've a project to do using both MPI and OpenMP and with the actual installation of MPI I cannot compile using the following command: mpicc -openmp "test_omp.c" -o "test_omp". It gives me the following error: Not defined function omp_get_thread_num(); and moreover, it ignore my #pragma commands.
Your problem is that you are giving the compiler the wrong option to enable the OpenMP support. -openmp is only understood by the (commercial) Intel compiler, which is probably the tool-set installed on the site you've referred to in your other question. Most Linux distributions come with GCC and one is to assume that mpicc will use GCC (check with mpicc -showme).
The option to enable OpenMP support in GCC is -fopenmp (notice the f).

Installing Clang/LLVM/Ubuntu

I am required to use LLVM and Clang for a compilers class I am enrolled in. This is not a question about the content of the class, just how to get the required software installed.
I am running gcc version 4.6.3 and have downloaded, built, tested, and updated what I believe to be LLVM suite version 3.4 (the latest svn edition). I do a simple "hello world" application, as referenced on the LLVM getting started page, but on the line
lli helloworld.bc
I get the error "lli:helloworld.bc: Invalid MODULE_CODE_GLOBALVAR record"
Here are the instructions I ran in the terminal, most of which was taken directly from the LLVM website:
cd myFolder
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd myFolder
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd myFolder
cd llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd myFolder
mkdir build
cd build
../llvm/configure --enable-optimized CC=/usr/bin/clang CXX=/usr/bin/clang++
make
make check-all
make update
THEN
clang hello.c -o hello
clang -03 -emit-llvm hello.c -c -o hello.bc
lli hello.bc
And that final line, lli hello.bc, is where I get the error above.
Here are my questions:
What is installed on my machine? How do I resolve this error?
My professor said we need clang and LLVM 3.3. How can I get LLVM 3.3?
When you typed:
clang -03 -emit-llvm hello.c -c -o hello.bc
You used the system's clang executable, which is at /usr/bin/clang, and is not the clang you have just built. The two have a different version. lli, however, is the lli you've just built - Ubuntu doesn't come with it. That means you have generated a .bc file with an older LLVM version and then tried to run it with a newer LLVM version, hence the problem.
To verify this, you can check which clang you are using by typing which clang into the console.
The simplest way to remedy this is to type ./clang (or any other path which isn't just the file name) instead of clang, which forces the shell to choose the file in the current directory.

openindiana node compiling error no C compiler

I am trying to compile node.js on openindiana, below is my Environment,
Even I set gcc path in .profile
It keeps saying
No acceptable C compiler found!
export PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/gcc/4.4.4/bin:/usr/gnu/bin:$PATH
export PAGER="/usr/bin/less -ins"
export CC=/opt/gcc/4.4.4/bin/gcc
export cc=/opt/gcc/4.4.4/bin/gcc
run
$ CC=gcc ./configure --with-dtrace --dest-cpu=x64 --prefix=~/local
or
$ ./configure --with-dtrace --dest-cpu=x64 --prefix=~/local
both of them gives following error
Node.js configure error: No acceptable C compiler found!
Please make sure you have a C compiler installed on your system and/or
consider adjusting the CC environment variable if you installed
it in a non-standard prefix.
nick#www:~/node-latest-install$ echo $PATH
/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/gcc/4.4.4/bin/gcc
nick#www:~/node-latest-install$ which gcc
/usr/bin/gcc
nick#www:~/node-latest-install$ which cc
which: no cc in (/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/gcc/4.4.4/bin/gcc)
nick#www:~/node-latest-install$ gcc -v
Using built-in specs.
Target: i386-pc-solaris2.11
Configured with: /home/jt/OI-151A-STABLE/151A-PRESTABLE6/newbuilds/oi-build/components/illumos-gcc/richlowe-gcc-f268959/configure --prefix=/opt/gcc/4.4.4 --with-gnu-as --with-as=/usr/sfw/bin/gas --with-ld=/usr/bin/ld --without-gnu-ld --enable-languages=c,c++,objc --enable-shared --with-mpfr-include=/usr/include/mpfr --with-gmp-include=/usr/include/gmp
Thread model: posix
gcc version 4.4.4 (GCC)
if you specify CC variable, make it absolute path to gcc: CC=/opt/gcc/4.4.4/bin/gcc. But if compiler is already in PATH, specifying CC shouldn't be necessary.
This may sound like a stupid answer but have you tried removing it and re-installing it from package manager. GCC that is
Also when did the problem start occurring? You could use beadm to roll back the OS to the last update or to when you created a 'Restore Point' so to speak. Check it out, very useful thing to use before running installs.

Setting up G++ or ICC for mpi.h on Ubuntu

I have never done any major programing outside of VS08.
I am trying to compile a program called LAMMPS with either of the two relevant make files. One calls g++ and the other calls icc (Intel's compiler).
icc produces this error:
icc -O -DLAMMPS_GZIP -DMPICH_SKIP_MPICXX -DFFT_FFTW -M write_restart.cpp > write_restart.d
write_restart.cpp(15): catastrophic error: cannot open source file "mpi.h"
#include "mpi.h"
and g++ throws this error
g++ -g -O -DLAMMPS_GZIP -DMPICH_SKIP_MPICXX -DFFT_FFTW -M verlet.cpp > verlet.d
pointers.h:25: fatal error: mpi.h: No such file or directory
compilation terminated.
The mpi.h file is located in /usr/lib/openmpi/include
It is my understanding that I need to set that $PATH variable which reads
bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/opt/intel/bin:/usr/lib/openmpi/include:
and $LD_LIBRARY_PATH which currently reads
/usr/lib/openmpi/lib:
SO, how does one include the mpi.h file? So that either icc or g++ find it?
mpi.h is a header for MPI library. That would be included if you use mpic++ MPI compiler wrapper instead of g++ in your makefile. mpic++ will call the appropriate compiler. From what you describe you have openmpi package installed on your ubuntu machine.
For more info, you need to consult the manual, e.g.
http://lammps.sandia.gov/doc/Section_start.html#2_2 (for LAMMPS)
and perhaps you need to see openmpi manual as to how to set up additional compiler. Not sure if this can be done after openmpi itself has been built. By default I think in Ubuntu openmpi compiler wrappers would only call g++. CMIIW.
Okay, so I got it to work with g++ when setting up cc as "mpic++.mpich2" instead of "mpic++"
you can try compile using openmpi make file in /src/MAKE
make openmpi
in my case, this option was successful

Resources