在Eclipse 4.4.2中使用C代码中的Build Variables [英] Using Build Variables in C code with Eclipse 4.4.2

查看:470
本文介绍了在Eclipse 4.4.2中使用C代码中的Build Variables的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以前使用Eclipse 3.5.2创建的项目。在其中,我能够在项目属性中设置构建变量。在这种情况下,假设我将 SW_VERSION 设置为4403。现在这是一个十六进制数,因此在构建设置中,我添加了一个符号 VERSION = 0x $ {SW_VERSION} 条目。然后在我的代码中,我可以将 VERSION 用作常规数字,例如:

I have a project that I created previously using Eclipse 3.5.2. In it, I was able to set a Build Variable in the project properties. In this case, let's say I set SW_VERSION to be 4403. Now this is intended to be a hex number, so in the Build Settings, I added a Symbol "VERSION=0x${SW_VERSION}" entry. Then in my code, I was able to use VERSION as a regular number, like so:

unsigned int vers = VERSION;

没有问题, vers 0x4403

现在我正在使用Eclipse 4.4.2版,并使用一些新功能。但是首先,我只是尝试使用新的工具链重新编译我的旧项目,并且虽然我在控制台上没有收到任何消息,但在问题选项卡中却收到3条警告:

Now I'm using Eclipse version 4.4.2 and I'm updating my project with some new features. But first I'm just trying to re-compile my old project with the new toolchain, and while I don't get any messages on the Console, I get 3 warnings in the Problems tab:

Symbol 'SW_VERSION' could not be resolved
Symbol '$' could not be resolved
Statement has no effect 'VERSION'

我还没有尝试运行已完成的项目,但是这让我和我都感到担忧假设它实际上不会像以前那样工作。在新的Eclipse中,是否有其他方法可以做到这一点?或者只是消失了此功能?

I haven't tried running the completed project yet, but this concerns me and I have to assume that it won't actually work like it used to. Is there some different way to do this in the newer Eclipse or is this feature just gone?

作为一个附带说明,我这样做是有原因的。我在工件名称的末尾附加了 SW_VERSION 的值。

As a side note, there is a reason why I did it that way. I also have the value of SW_VERSION appended to the end of my artifact name. That part still works at least.

推荐答案

索引器(CDT解析器)会看到您的VERSION宏并将其扩展为0x $ {SW_VERSION}
但不对其进行评估,因此会将其未经扩展地传递给预处理器,
这些警告来自静态代码分析,不会影响您的二进制文件。但是,由于令人烦恼的是您不得不通过仅为索引器定义VERSION宏来强制索引器正确查看此宏

Indexer (CDT parser) sees your VERSION macro and expands it to 0x${SW_VERSION} but does not evaluate it so it passes it to preprocessor as is unexpanded, these warning are coming from static code analysis and wont affect your binary. But since it annoying to see that you have to force indexer to see this macro properly by defining VERSION macro for indexer only


  • 项目属性-> C / C ++常规->预处理程序..->

  • 选择GNU C(或您使用的任何语言变体)->

  • 选择CDT用户设置条目

  • 单击添加...并添加预处理器宏 VERSION = 1

  • project properties->C/C++ General->Preprocessor ..->
  • Select GNU C (or whatever language variant you use)->
  • Select CDT User Setting Entries
  • Click Add... and add "Preprocessor macro" VERSION=1

它不管您输入的数字是多少,因为它不会出现在二进制文件中,而只是用于语法分析。

It does not matter what number you put there since it won't be in your binaries, it is just for syntax parsing.

这篇关于在Eclipse 4.4.2中使用C代码中的Build Variables的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆