【发布时间】:2014-03-21 17:08:22
【问题描述】:
我正在开发一个 Eclipse 插件,它必须检查当前 C 项目中设置了哪些编译器选项。 基本上,我想访问 Properties -> C/C++ Build -> Settings -> GCC C Compiler -> All options 字段。
我已经搜索了如何访问它,但我还没有找到方法。 我尝试通过以下代码中的首选项访问它:
IEclipsePreferences root = Platform.getPreferencesService().getRootNode();
我可以通过这种方式访问我的插件的首选项,但不能访问 C 项目的首选项。
有人知道怎么做吗?我不需要更改编译器选项,只需知道设置了哪些标志。
更新:我找到了解决方案。
IResourceInfo info = getResourceInfo(translationUnit, description);
ITool tools[] = info.getTools();
for (ITool t : tools) {
if (t.getName().compareToIgnoreCase("GCC C Compiler") == 0) {
try {
//Finally the field I was looking for
String commandLine = t.getToolCommandFlagsString(getProject().getFullPath(), null);
} catch (BuildException e) {
e.printStackTrace();
}
}
}
然后我可以解析字符串,虽然不理想,但可以。 我从这篇文章中得到了 getResourceInfo() 函数:How do I programmatically change the Eclipse CDT tool settings for a file?
所以,感谢 justinmreina 的回答!
【问题讨论】:
标签: gcc eclipse-plugin eclipse-cdt