简体   繁体   中英

Intel <math.h> vs C <math.h>?

I have a C++ project on Linux where I have included the library path:

/opt/intel/include/

so that I can use certain Intel libraries. However, I also wish to use the standard C/C++ math.h so that I can call pow(x,y) ;

I included <math.h> and used using namespace::std and then made a call using pow(x,y) . The compiler (gcc4.7) complains:

/opt/intel/include/math.h:27:3: error: #error "This Intel is for use with only the Intel compilers!"

How do I specify that I am referring to the C/C++ math.h pow() and not the Intel pow() ?

This is the reason C++ uses namespaces for this sort of thing and also uses more specific header names that are less likely to collide with other libraries.

If you #include <cmath> (which you ought to in C++ software, rather than <math.h> ) you can distinguish between the stdlib's implementation and Intel's by using std::pow (...) . This is another reason not to apply using namespace std; willy-nilly as well, it might make code appear cleaner, but since the function names used in the stdlib are so generic they frequently collide with other libraries.

It seems the #error in Intel's <math.h> is rather blunt and obvious: The header is guarded against use with other compilers, probably because it depends on specific extensions (eg, built-in functions) not available in other compilers. If it really is <math.h> it would be part of the standard C or C++ library and as such tied to the compiler unless it is explicitly part of the platform ABI which doesn't seem to be the case.

It doesn't quite look as if you want to use Intel's <math.h> but only other headers from Intel's library. In that case one of the following techniques may work:

  1. Specify the location of the system/gcc <math.h> with another -I option preceding the one for Intel's headers: the order in which headers are searched is generally the same order in which the -I options appear.
  2. Do not use a -I directive to find Intel's headers but include them with a path name or with a relative path name (the latter in combination with a -I option, eg, -I/opt/intel ).
  3. Create a custom directory with symbol links to the headers/directories in /opt/intel/include and remove any header which you want to get picked up from somewhere else. Alternatively, work the other way around: create a symbolic link to each header needed from /opt/intel/include .

Since this directory doesn't seem to be constructed to be usable as a drop-in for other compilers, it is quite possible that none of this won't work: headers shipping with a specific compiler have a tendency to be specific to that compiler. For example, you'll also need to link to the corresponding Intel libraries and I'm not sure if the Intel compiler and gcc use the same ABI (on Linux they may use a common ABI, though).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM