-fopenmp does not include omp.h on amazon linux? - amazon-web-services

I'm trying to compile a test openmp program on an Amazon AWS t2.micro instance. It seems to have trouble. Upon trying to compile this OpenMP hello world program, the compiler fails to find omp.h despite using gcc hello_world.c -fopenmp.
After that, I tried running locate omp.h and found it in /usr/lib/gcc/x86_64-amazon-linux/4.8.5/include. I next attempted to compile by including that directory with gcc -I. Then, the compiler still needed libgomp.spec, which has been encountered and solved in this stack overflow question.
Following the most upvoted answer on there by creating some symbolic links did nothing for me and still says error: libgomp.spec: No such file or directory, even though libgomp.spec is in my /usr/lib64 directory.
So, what can I do to fix this, and why won't -fopenmp work on amazon linux like expected? This is done on an instance which was created by CfnCluster, if that helps.

As usual, header files such as omp.h come with relevant version of gcc compiler. When the compiler can't find the header file, I guess you are using the different version compiler (other than 4.8.5 in this case).
You can find all gcc versions by typing:
sudo yum list installed | grep gcc
If there are other versions of gcc such as gcc72, you can erase them by:
sudo yum erase gcc72
After that, you will compile the code successfully.

Exactly, as told #S.Takezawa , currently only gcc 6.4 installation supports libgomp (fopenmp) and supports modern c++14 standard on Amazon AMI linux.
gcc4.7 is too old. So this helps for me:
sudo yum install gcc64-c++.x86_64 libgcc64.x86_64

Related

How to recover system gcc compiler on centos 6

I am running centos 6 on a cluster. I installed the latest gcc-8.2.0. and made a link "ln -sf /usr/bin/gcc-8.2 gcc".
I did the same for g++ and gfortran.
I wanted to reinstall gcc-8.2.0 and went ahead to
make clean
in the gcc-8.2 directory.
When I try
./configure
I get that C compiler cannot create executables
The links I made are broken.
The system gcc-4.4.7 cannot be found
which gcc
gives no gcc
sudo yum install gcc gcc-c++
gives gcc is already installed.
I tried to install an rpm, which fails because of dependencies.
I have pg compilers installed in /opt/pgi
When I configure with
CC=/path to/pgi/bin/pgcc FC=/path to/pgi/bin/pgfortran ./configure
I still get C compiler cannot create executables
I tried the following c++ programm
#include <iostream>
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
With the command
/opt/pgi/linux_86_64/12.08/bin/pgcpp hello.cpp -o hello
It gives compilation error that float.h not found. On another linux PC with working gcc, the program works with the command
g++ hello.cpp -o hello
I will appreciate any assistance to either find the systemgcc or use pg compilers to compile gcc if possible
I admit it is a big mess which will require OS reinstallation and reconfiguration. But then I did
sudo yum install compat-gcc-34
Now I have gcc34 and configure of gcc-8.2 goes through without "c compiler cannot create executables". (Note that the ./configure referred to in earlier post was actually
../gcc_8_2_release/configure
inside "gcc_8_2_release_build, so gcc was not being built in its source directory.
The problem I have now is with make, which needs g++, giving error
uint_t(64) or int_t(64) not found.
Thanks all who have gone through this post, for your patience.
Any assistance will be appreciated.
Here is how I got out of this mess.
With the following two commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
I was able to install the older version of gcc, c++ and g77. Then I was able to build gcc-8.2.
Now I have a functional system with the latest gcc, yes it may need re-installation/re-configuring but it is fully functional.
I have learnt a lot and very much appreciate the comments and guidelines of #Basile. However, at one point he was rather negative and discouraging.
But thanks to my belief and perseverance, and more importantly browsing the knowledge shared by others, I have been able to recover what I was beginning to be convinced was a lost cause.
Thanks all.
This is more a sysadmin question than a programming one.
My recommendations:
don't mess your /usr/bin/. Leave your package manager yum to fill it -and never add anything inside it without yum ; so remove manually any symlinks you made there (by mistake)
reinstall the old system gcc 4.4 and g++ 4.4 (using yum)
rebuild your GCC 8 from scratch from its source code. Configure it with --program-suffix=-8 (but no --prefix, or a --prefix=$HOME/soft/ if you don't have root access). So it will install /usr/local/bin/gcc-8 and /usr/local/bin/g++-8 etc... (or, if you have given --prefix=$HOME/soft/ , a $HOME/soft/bin/gcc-8 etc...)
create a $HOME/bin/ if you don't have already one
be sure to have $HOME/bin/ early in your $PATH (before /usr/bin/)
add a symlink ln -sv /usr/local/bin/gcc-8 $HOME/bin/gcc and likewise for g++ etc..
Then, when you type gcc you are getting that symlink to /usr/local/bin/gcc-8 etc.
If you cannot write to /usr/local/ (e.g. because you don't have root permission...) you could pass --prefix=$HOME/soft/ to GCC 8 .../configure then replace /usr/local/ above with $HOME/soft/
If you are the sysadmin and can write to /usr/local/ and have to set up things for many users: add a symlink ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc etc and ask your users to put /usr/local/bin/ in their $PATH before /usr/bin/
BTW, notice that it is explicitly documented that GCC 8 (or others) need to be built outside of its source tree: in Installing GCC you can read:
First, we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree.
(the "highly recommend" should be considered as a polite way to say "you absolutely should")
So your ./configure was another mistake.
It could happen that you messed up your system more seriously than you thought (and perhaps you need to reinstall, or to call Redhat support).
PS. I don't know Redhat (used it only in the previous century). My favorite distro is Debian/testing or Debian/unstable (and my computers are desktops, not clusters).
This problem was solved by the following commands
sudo yum install compat-gcc-34-c++
sudo yum install compat-gcc-34-g77
Once this older version of gcc is installed, the latest version, gcc-8.2 was built and the system is no longer messed terribly. It is very healthy and fit.

ld for Clang installation

I installed CLang on CentOS using sudo yum install clang. Then tried using it by firing this command clang++ main.cpp -o main. This complained of missing ld.
Prior to this I had deleted the usr/bin/ld
I read that llvm has it's own linker; I am unable to find one. I also read that llvm lld was removed and the documentation says that one can make do with Clang only. Given that I have removed /usr/bin/ld, how do I get it back? Do I need to get it back? How do I make CLang use the linker that is supposed to be included with Clang?
I am debugging an issue and to one of the steps in trying to fix the issue was to reinstall the compiler, hence I resorted to deleting all the previously installed packaged and files, including ld.

How to use previous versions of g++

I am currently running a debian Jessy whose g++'s version is 4.9. For some reason I need to compile a code in g++-4.7 or previous version.
I got the files of gcc-4.7 and g++-4.7 from a debian wheezy of a friend who has g++-4.7.
I tried to make the apt-get install, it seemed to have worked for the gcc but not for the g++. I put the files in the /bin, but he doesn't seem to locate the g++-4.7 package.
When I try to compile my code I specify g++-4.7 but get the error :
g++: error trying to exec 'cc1plus': execvp: No such file or directory
Any idea how to figure this out?
My advise is to add the wheezy repositories to /etc/apt/sources.list and then install g++-4.7 using apt-get. Using this method you will also get bugfixes etc.
I guess, currently you're just having dependency Problems. These will be solved when you use apt-get.
It is very easy to install gcc from sources. Remember that you have also to use a binutils version which maps to the gcc version. Mostly it is possible to run older gcc versions on actual binutils, but I have also seen a problem during install.
I have installed a long list of gcc versions in /opt/
Simply copy an older gcc version somewhere in the file system can result in problems with using the correct library versions.
If you install different gcc versions and also the related libraries e.g.libstdc++ , don't forget to update your library data base ( ldconfig/LD_LIBRARY_PATH/...) Maybe http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html can help.

OpenMP on Mac not working anymore

I had OpenMP compiling and executing in C/C++ on my Mac but then I formatted and reinstalled a fresh copy of OS X. I believe the only difference in the setup was that I had Xcode 5 before the format, and now I have Xcode 6.
Now I get fatal error: 'omp.h' file not found
I read this has something to do with clang and gcc, but, my confusion lies with why did it work before and now its not working?
After some research I seem to have found an answer.
GCC included in the latest version of Xcode (Xcode 6) is only a symbolic link to clang. Since clang does not support OpenMP at this time, you need to install a different version of GCC. The easiest way to do this would be to use Homebrew or MacPorts.
Keep in mind that even when you do this you will probably need to alter your $PATH to have /usr/local come before /usr/bin. This is because Homebrew will have placed your newly installed GCC in /usr/local. Also, some implementations may name the command gcc-49 instead of plain gcc.
Mac OSX uses clang.The gcc compiler in OS X does not support OpenMP. To use this feature a new gcc compiler needs to be installed.
Go to Terminal, if you have not installed Hombrew, install it:
/usr/bin/ruby -e "$(curl -fsSL https://`enter code here`raw.githubusercontent.com/Homebrew/install/master/install)"
then install new version of gcc
brew reinstall gcc --without-multilib
This will not make changes to the existing gcc compiler installed by Xcode as we are reinstalling it.
After running the command given below compile the files using the new version of gcc using the syntax : gcc-version -fopenmp filename.c
To find the version type gcc and then press tab. This will list out all the possible variants of gcc. The version number can be found out from this. For example : gcc-6, gcc-4.9,etc

Update GCC on OSX

So I am a new programmer and I just installed XCode on my Macbook to get the GCC. I think Xcode is the only way for getting GCC on OSX. Now when I run my Hello World application, in C++, g++ comes up saying it is version 4.0.1 but when I look for commands starting with g I also see g++-4.2. Is there any way of making 4.2 default rather than 4.0.1, and also is there a way to updating gcc to the latest version 4.4.0?
EDIT: Ok, so I installed macports and installed gcc4.4 and it shows up on terminal as gcc-mp-4.4 and how do I make it default with gcc_select, like what are the commands and stuff. Thanks.
If you install macports you can install gcc select, and then choose your gcc version.
/opt/local/bin/port install gcc_select
To see your versions use
port select --list gcc
To select a version use
sudo port select --set gcc gcc40
I know it is an old request. But it might still be useful to some. With current versions of MacPorts, you can choose the default gcc version using the port command.
To list the available versions of gcc, use:
$ sudo port select --list gcc
Available versions for gcc:
gcc42
llvm-gcc42
mp-gcc46
none (active)
To set gcc to the MacPorts version:
$ sudo port select --set gcc mp-gcc46
I'm just dropping in to say that using a soft link to accomplish this is a terrible, no-good, horrible idea.
One of the key things about writing software is reproduceability - you want to be able to get the same results every time. These systems are so complex that you want to reduce all invisible sources of error.
Having a soft link is an invisible source of error. It's the sort of thing you'll forget in a month, then move to a different machine, and wonder why you are getting different results - or, you'll try to upgrade your system, and you'll get weird errors because it's not expecting a softlink there.
Moreover, this isn't guaranteed to work - in particular, it's not clear that you will get the correct system include files, which have certainly changed between iterations of gcc.
gcc_select is a systematic way of doing the same thing which will work predictably, or in the very worst case you can file a bug report and get an eventual fix or fix it yourself.
Unfortunately :-( gcc_select does not affect which compiler XCode uses so it's not the way to go if you need to work in XCode (which I do). I still don't know what that way might be.
The following recipe using Homebrew worked for me to update to gcc/g++ 4.7:
$ brew tap SynthiNet/synthinet
$ brew install gcc47
Found it on a post here.
use "gcc_select -l"
>
gcc_select -l
gcc40 mp-gcc44
>
gcc_select mp-gcc44
You can have multiple versions of GCC on your box, to select the one you want to use call it with full path, e.g. instead of g++ use full path /usr/bin/g++ on command line (depends where your gcc lives).
For compiling projects it depends what system do you use, I'm not sure about Xcode (I'm happy with default atm) but when you use Makefiles you can set GXX=/usr/bin/g++ and so on.
EDIT
There's now a xcrun script that can be queried to select appropriate version of build tools on mac. Apart from man xcrun I've googled this explanation about xcode and command line tools which pretty much summarizes how to use it.
in /usr/bin type
sudo ln -s -f g++-4.2 g++
sudo ln -s -f gcc-4.2 gcc
That should do it.
You can install your GCC manually
either through
sudo port install gcc46
or your download the source code from one of the mirrors from here for example here
tar xzvf gcc-4.6.0.tar.gz
cd gcc-4.6.0
./configure
make
well if you have multiple version, then through you can choose one
port select --list gcc
remember port on mac is called macport https://www.macports.org/install.php and add add the bin into your path export PATH=$PATH:/opt/local/bin
Whatever Apple ships as the default gcc in xcode (4.2.1 on 10.6, 4.0.1 before) is well tested (and maintained) by the apple guys and the "standard" to build software with on OS X. Everything else is not, so think twice if you want to develop software, or be gcc/OS X beta tester.