简体   繁体   English

在Makefile中设置编译器名称

[英]Set compiler name in the Makefile

I have a Makefile suppose to compile my app in multiple host, some of them has built in intel compiler (icpc) and others just have g++. 我有一个Makefile假设在多个主机中编译我的应用程序,其中一些内置了intel编译器(icpc)而其他人只有g ++。 I would like that makefile automatically detect availability of icpc and if it is available, compile application with intel compiler, otherwise just compile it with g++. 我想makefile会自动检测icpc的可用性,如果可用的话,用intel编译器编译应用程序,否则只需用g ++编译它。

How do I have to change Makefile to automatically detect availability of icpc compiler ? 如何更改Makefile以自动检测icpc编译器的可用性?

Here is my try which simply did not work 这是我的尝试,这根本不起作用

ERR = $(shell icpc 2>/dev/null ; echo $? )
ifeq "$(ERR)" "127"
    CXX = g++
else
    CXX = icpc
endif

You can use which for detecting icpc instead. 您可以使用which来检测icpc Also better check against 0 instead of 127 , since there may be differences from one system to another 也可以更好地检查0而不是127 ,因为从一个系统到另一个系统可能存在差异

ERR = $(shell which icpc >/dev/null; echo $$?)
ifeq "$(ERR)" "0"
    CXX = icpc
else
    CXX = g++
endif

all:
    echo $(CXX)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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