Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7942 Discussions

how do i know if program is compiled by g++ or intel compiler

suanhwee
Beginner
1,529 Views
Hi,
Is there a define that intel compiler or g++ sets to inidicate that the program is compiled by the intel compiler or g++ can i detect it during runtime from the source code?
I have been looking around but i just cant find those defines.
Thanks
0 Kudos
1 Solution
TimP
Honored Contributor III
1,529 Views
Quoting - suanhwee
Is there a define that intel compiler or g++ sets to inidicate that the program is compiled by the intel compiler or g++ can i detect it during runtime from the source code?
I have been looking around but i just cant find those defines.
Look up the pre-defined macros in the icc documentation, if that is your interest.

View solution in original post

0 Kudos
6 Replies
aazue
New Contributor I
1,529 Views
Quoting - suanhwee
Hi,
Is there a define that intel compiler or g++ sets to inidicate that the program is compiled by the intel compiler or g++ can i detect it during runtime from the source code?
I have been looking around but i just cant find those defines.
Thanks
Hi
Use ldd /path..../program function system() in your source or in shell (easy side).
see also source ldd.
Add futures in your source an parameter for name compiler main(.... argv.... better.
Kind regards
If program call money licence is Icc....

0 Kudos
TimP
Honored Contributor III
1,530 Views
Quoting - suanhwee
Is there a define that intel compiler or g++ sets to inidicate that the program is compiled by the intel compiler or g++ can i detect it during runtime from the source code?
I have been looking around but i just cant find those defines.
Look up the pre-defined macros in the icc documentation, if that is your interest.
0 Kudos
SamuVish
Beginner
767 Views

In Linux, for example, I use objdump to check the compiler ... as like

$ objdump -s --section .comment /path/to/your/binary/or/library

 

 

0 Kudos
suanhwee
Beginner
1,529 Views
Quoting - tim18
Look up the pre-defined macros in the icc documentation, if that is your interest.
thanks for helping me out
0 Kudos
Dale_S_Intel
Employee
1,529 Views
Quoting - suanhwee
Hi,
Is there a define that intel compiler or g++ sets to inidicate that the program is compiled by the intel compiler or g++ can i detect it during runtime from the source code?
I have been looking around but i just cant find those defines.
Thanks

Forgive me if your question has already been answered, but I thought I'd add some clarification just in case. There are at least two ways I can interpret your question. If you want to tell at compile time, i.e. in the source while it's being compiled, that's pretty straightforward. The recommended macro to rely on is __INTEL_COMPILER, which is set to the compiler version (e.g. the 11.1 compiler is 1110). If that is defined, you know you're building with the Intel compiler. The other question you might be asking is if you've got an executable, can you tell if it was built with icc or gcc, that's trickier. If you're building the exceutable you can build something into it to answer that question at runtime using the above mentioned macro. If you've got a mystery executable and you're wondering how it was built, well that's a more complicated question.

Hope that helped.

Dale

0 Kudos
TimP
Honored Contributor III
1,529 Views
The other question you might be asking is if you've got an executable, can you tell if it was built with icc or gcc, that's trickier. If you're building the exceutable you can build something into it to answer that question at runtime using the above mentioned macro. If you've got a mystery executable and you're wondering how it was built, well that's a more complicated question.


In a gcc built object, you would expect an ascii string such as "gcc compiled," which you could see with the strings command. If you wished an embedded string from an icc compile, you could use -sox, or, as Dale said, put one in yourself.
A dead give-away is the presence or absence of the _intel_ run-time library functions in place of standard glibc equivalents.
0 Kudos
Reply