How icc/icpc uses GCC on LInux?

How icc/icpc uses GCC on LInux?

Hello,

I would greatly appreciate if someone could explain me or point to some references about the following topic:

How icc/icpc/ifort uses GCC and/or system libraries (like libc)? Are those things related to each other?

What is the actual impact of the following command line compiler options to compilation/linkage? Options of interest:

-gcc-name,

-gcc-version,

-gxx-name. 

-cxxlib=dir

-cxxlib-nostd

-no-cxxlib

I've read corresponding sections of manual but it do not give too much information.

The reason for my question is that reacently I've try to build some application and It did not compiled without command-line options, but did compile (and link) when I used some of these switches. I want to understand what is the relation between GCC and icc and what actual impact these switches make to the compilation/linkage process.

Thanks.

9 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

>>...The reason for my question is that reacently I've try to build some application and It did not compiled without command-line
>>options, but did compile (and link) when I used some of these switches.

A GCC compiler always requires a set of some options. I also checked my docs for these switches:

-gcc-name
-gcc-version
-gxx-name
-cxxlib=dir
-cxxlib-nostd
-no-cxxlib

and I haven't found anything (!). Did you read descriptions for these switches on some web site?

 

icc and icpc are only compilers.They use the GNU tools on the system. So for example, they use the GNU header files like stdio.h and GNU linker and libraries. For these reasons the compiler has to be compatible with GNU -- for example if you have GNU version 4.6 on your system, icc/icpc tries to act just like GNU 4.6 (with the same features and bugs). 

So the compiler will try to figure out which version of GNU you have installed by looking at the gcc or g++ in your PATH. You can override this behaviour by using some of the -gcc switches above.

The cxxlib switches have to do with linking in the GNU C++ library libcxx.

Please read the documentation and if you have a specific question please ask. Do an icpc -help for documentation. 

Judy

Hello, Sergey, Judith.

Thanks for your comments.

@Sergey Kostrov

Sorry I did not get your idea. It seems that you misunderstood the question. The question was not about GCC, but about icc/icpc/ifort (and their relation to GCC.

@Judith Ward

Quote:

Judith Ward (Intel) wrote:

icc and icpc are only compilers.They use the GNU tools on the system. So for example, they use the GNU header files like stdio.h and GNU linker and libraries. For these reasons the compiler has to be compatible with GNU -- for example if you have GNU version 4.6 on your system, icc/icpc tries to act just like GNU 4.6 (with the same features and bugs).

The Idea in general is clear. But the details are fo interest. For example, when I compiled application with different flags in one case I got compilation error (not linkage) and in other case (i've specified -gcc-name and -gcc-version) I did not get these errors. This means, that compiler behaves differently (treat code differently), when these options are supplied.

So the question is: What exactly changes? Are there some imposed "Defines" or it just parses the code differently or something else?

For example, say, I have two "system" versions of GCC installed on my linux system: GCC 4.4 (standard, current) and GCC3.4 (legacy, compatibility). And I have code, that can be compied with, e.g. 3.4 and cannot be compiled with 4.4. Does it mean, that if I compile the same code with icc, then specifying -gcc-version or -gcc-name (or both) to particular version of GCC, then the behavior will be the same?

Quote:

Judith Ward (Intel) wrote:

So the compiler will try to figure out which version of GNU you have installed by looking at the gcc or g++ in your PATH. You can override this behaviour by using some of the -gcc switches above.

The cxxlib switches have to do with linking in the GNU C++ library libcxx.

Please read the documentation and if you have a specific question please ask. Do an icpc -help for documentation.

This is another, less general and more technical question: which flags are enough. How icc/icpc searches for GCC (of specific version).

For example, if I do not provide any of those flags, then I guess, gcc will try to find, which executable will be launched if "gcc" command is invoked. Then it tries to figure out its version and enables corresponding "features" (effectively sets -gcc-version to this version).

Again, my guess, that if we set -gcc-name to some specific gcc executable (and not -gcc-version), than icc will try to execute it, find out the version and set corresponding value for -gcc-version. Is it right?

Now let's assume we've set -gcc-version option. Will the compiler search for the GCC of this version or it will just check, that default "gcc" have correct or incorrect version and "fail" if the version is incorrect? If it does search, how it does it? Do it tries to search for the command like "gcc<version" or "gcc-"version" or smth. like that?

What will happen if we define both: -gcc-name and -gcc-version, which contradict each other?

 

Other questions are related to interrelations between gcc and g++:

if we set e.g. -gcc-version to non-default, does it mean that g++ will either be called of this specified versoin?

if we set -gcc-name (and as I guessed before compiler understand, that it have non-default -gcc-version) which version of c++ will be used?

Why there is no -gxx-version option? (by analogy with -gcc-version), or if we gan use -gcc-version when compiling C++, why there is -gxx-name (why cannot we just use gcc-name? or we can?).

What will happen if we define -gcc-name and -gxx-name and they point to executables from different GCC versions?

 

And questions about linkage:

What is the impact of -cxx-lib=dir? Why it points to the directory, not to the file?

Does it only have impact on link time or on compile time either (I mean, if I use -c -cxxlib=dir, will the -cxxlib=dir be ignored or it will influence compilation somehow)?

What is the difference betwen flags -cxxlib-nostd and -no-cxxlib? Are these options intended to be used, when I want to compile/link my application with custom (non-system and may be even non-gcc) standard C++ library line stl-port?

Why there is no such options for standar C library (only for C++)?

 

I've asked many questions. If at least some of them will get answers I will really appreciate it.

Thanks in advance.

Dmitry.

In an upcoming release of the compiler, we expect that the -gcc-version option is going to be deprecated, and we'll recommend that it not be used.  There are 2 ways to select your desired version of gcc, one is through establishing your environment (path variable) and the other is by using the option -gcc-name.  Can you give more background about what you're trying to find out?

ok let me try to start to answer your questions...

The -gcc-version flag can effect the compilation in hundreds of ways. For example, if you specify -gcc-version=340 the compiler will try to act just like GNU version 3.4. If you specify -gcc-version=460 the compiler will try to act like GNU version 4.6. This can effect name lookup, function matching, which C99 or c++11 features or GNU features are enabled, to name just a few of the hundreds of differences. So it's not suprising to hear the a program can be successfully compiled or not depending on the value of the switch. -gcc-version only effects the behavior of the compiler itself, it does not effect what GNU headers or libraries are used. It affects both C and C++ so there is no need for a different switch called -gxx-version.

The gcc-name will tell the compiler which gcc to use (instead of the one found in your PATH) and then the compiler will figure out from that which version of gcc is being used (by doing a gcc -v) and implicitly set the right gcc-version for the compiler. In particular the C++ standard library files that are shipped with say GNU version 4.6, are unlikely to compile if you specify -gcc-version=340. So you either shouldn't specify -gcc-version or you should make sure that the -gcc-version you specify matches the version of the GNU header files and libraries that you are using.

None of these switches are necessary -- as I said the default behaviour of icc or icpc is to look at the first gcc or g++ it finds in your PATH. Then it will figure out which gcc version and set it automatically. If you set both -gcc-name and -gcc-version then you are probably doing something wrong, since the compiler will figure out -gcc-version by looking at the gcc that you've pointed at. Note that -gcc-name and -gxx-name will not only implicitly set -gcc-version for the compiler but will also affect where the GNU headers and GNU libraries are used.

The reason -cxxlib requires a directory argument is it indicates where all the GNU headers, binaries, and libraries are going to be used. i.e. there are multiple libraries libcxxstdc++, libmudflap, libomp, etc. For example let's says you had a GNU 4.5 distribution that was located here:

sptxl8-123> ls /rdrive/ref/gcc/4.5.0/rhel50/x86
bin  include  lib  libexec  share
sptxl8-124> icpc -cxxlib=/rdrive/ref/gcc/4.5.0/rhel50/x86 x.cpp

The switch will cause the compiler use the include files from include and use the libraries from lib in //. The compiler should also set -gcc-version to 450 automatically. You could do the same thing by specifying -gxx-name=/rdrive/ref/4.5.0/rhel50/x86/bin/icpc.

-cxxlib-nostd only effects the C++ standard library. It tells the compiler to not search the C++ system include directories so for exampe #include <iostream> will not compile but #include <stdio.h> will. It also prevents linking of  libcxxstd since the driver leaves off the -lcxxstd option.

-no-cxxlib is more general, it will also affect the linking of all C++ runtime libraries, not just libcxxstd. So a program that only uses printf, for example, will not link with -no-cxxlib option but will link with the -cxxlib-nostd option.

Not sure why there is nothing equivalent for the standard C library, my guess is noone has ever asked for such a thing.

If you set both gcc-name and gxx-name then gcc-name will be used whey you say "icc" and gxx-name will be used when you say "icpc".

I'm sure I haven't answered all your questions but I hope this is a start. If you want to experiment with these options yourself to see what the driver is doing you can add the -dryrun option and the compiler will show you the compile and link commands it would use if it was doing an actual compilation.

Judy

Just as a comment, libc isn't supplied as part of gcc.   On linux, it's a version of glibc, typically a fixed version for a given distribution, and gcc can be upgraded without changing glibc.  It's typically necessary to build on a platform which has the oldest libc version installed which you want to support, as binaries built for a given glibc are compatible at least with the following major version.

There is a libgcc2 which comes with gcc, generally containing functions such as double to unsigned int casts, but I haven't a case where it is a critical choice for icc.

libstdc++ does have to be kept consistent with the g++ version in use.  In the past, there were more versions of Intel C++ which gave you a choice between their own Dinkumware STL and libstdc++ than there are now, so the libstdc++ found on the current g++ path is the default on the usual platforms where g++ is available.

Hello everyone.

Lots of thanks to all who spent their time to answer my questions. Special thanks to Judith Ward (Intel) for elaborate answers to all my questions and to TimP (Intel) for his bunus answers to the questions, which I did not ask, but had in my head :).

Let me summarise the conclusions regarding practical applications of mentioned flags as I understood them (please, correct me if I'm wrong):

  1. Generally, we do not need -gcc-version flag. It is better to use -gcc-name or -gxx-name
  2. We should thinking about usage of -gcc-name option in one of the following situations:
  • We try to build  something, which cannot be compiled by the current version (default) of system compiler so we need to use legacy (compatibility) one. (This is my case) This is possible in case of 3rd party libs or in case of upgrade of the system (so that the default version of GCC is changed).
  • We want to use non-system version of GCC compiler. (I think, the most frequent case is when we want to use more recent version and build it from sources).

Small note to Intel insiders: I think, that it would be great if compiler references are extended with this kind of summary. I mean, it would be great to provide for each compiler options summary about the situations in which it is intended to be used (at least couple of examples).

Thanks again to everyone.

 

Yes I think your summary is correct. The -gcc-name option is also useful if for some reason you need to use different versions of GNU on one system. We have actually deprecated the -gcc-version option in our development compiler since it seems to just cause problems with users who use it incorrectly (and wonder why they are having problem compiling the GNU headers).

I submitted your documentation request in our bug tracking system as tDPD200240972. I was actually thinking the same thing as I started answering your questions...

thanks, Judy

Accedere per lasciare un commento.