安装完最新版(luna)的eclipse cpp(或eclipse java with cdt plugin)和nuwen后,新建c++ project并没有显示支持mingw toolchain. 打开属性有所提示“Toolchain “MinGW GCC” is not detected”。
而之前的一些eclipse版本是支持的,且没有任何特殊配置。
通过eclipse源码分析可知:新的eclipse由简单的check mingw的路径存在与否改变成check对应32版本的mingw32-gcc.exe和对应64版本的x86_64-w64-mingw32-gcc.exe,而nuwen安装之后存在的仅仅是gcc.exe,将此文件复制成对应的文件名即可呈现支持mingw toolchain.所以这个问题是由eclipse本身的代码改变所引起,与其他无关。
同时从源码可以看出,eclipse 32仅匹配mingw 32,而eclipse 64可以匹配mingw 32和mingw 64.
新版本的eclipse源码:
@Override
public boolean isSupported(IToolChain toolChain, Version version, String instance) {
IEnvironmentVariable var = new EnvironmentVariableManagerToolChain(toolChain).getVariable(ENV_PATH, true);
String envPath = var != null ? var.getValue() : null;
return MinGW.isAvailable(envPath);
}
}
/**
* Check if MinGW is available in the path.
*
* @param envPath - list of directories to search for MinGW separated
* by path separator (format of environment variable $PATH)
* or {@code null} to use current $PATH.
* @return {@code true} if MinGW is available, {@code false} otherwise.
*/
public static boolean isAvailable(String envPath) {
return isWindowsPlatform && findMingwInPath(envPath) != null;
}
private static String findMingwInPath(String envPath) {
if (envPath == null) {
// $PATH from user preferences
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_PATH, null, true);
if (varPath != null) {
envPath = varPath.getValue();
}
}
String mingwLocation = mingwLocationCache.get(envPath);
// check if WeakHashMap contains the key as null may be the cached value
if (mingwLocation == null && !mingwLocationCache.containsKey(envPath)) {
// Check for MinGW-w64 on Windows 64 bit, see http://mingw-w64.sourceforge.net/
if (Platform.ARCH_X86_64.equals(Platform.getOSArch())) {
IPath gcc64Loc = PathUtil.findProgramLocation("x86_64-w64-mingw32-gcc.exe", envPath); //$NON-NLS-1$
if (gcc64Loc != null) {
mingwLocation = gcc64Loc.removeLastSegments(2).toOSString();
}
}
// Look for mingw32-gcc.exe
if (mingwLocation == null) {
IPath gccLoc = PathUtil.findProgramLocation("mingw32-gcc.exe", envPath); //$NON-NLS-1$
if (gccLoc != null) {
mingwLocation = gccLoc.removeLastSegments(2).toOSString();
}
}
mingwLocationCache.put(envPath, mingwLocation);
}
return mingwLocation;
}
旧版本eclipse代码:
public class MingwIsToolChainSupported implements IManagedIsToolChainSupported {
@Override
public boolean isSupported(IToolChain toolChain, Version version, String instance) {
// Only supported if we can find the mingw bin dir to run the compiler
return MingwEnvironmentVariableSupplier.getBinDir() != null;
}