当使用预处理器时,哪个构建被考虑使用 [英] Which build to be considered for use when a preprocessor is used

查看:295
本文介绍了当使用预处理器时,哪个构建被考虑使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要在4.6和5.0版本的黑莓中使用的项目。
我在4.6和5.0版本中运行相同的代码,并附加了一些预处理指令(#ifndef语句,我需要使用5.0作为facebook sdk不支持4.6版本)
I有两个.cod文件(一个用于4.6,另一个用于5.0)
它们可以根据需要在各自的模拟器中工作。



但是,当我加载.cod文件4.6到5.0 ...(它将它视为预处理程序中的代码作为注释)
,当我这样做时,副作用 b
$ b

即从5.0到4.6 ...它说... projectname-1.cod没有找到。



类似的问题也在这里发布,请查看bbtool的评论说可以可能
黑莓中的两个不同版本(4.6,4.7和5.0 +以上)的一个构建

解决方案

<强>使用预处理器不是这样的方式对于不同的BB操作系统版本,请为一个单一的BUILD (无论您用于准备构建的工具)。



预处理器仅用于在编译/构建整个代码之前根据提供的条件删除/添加特定部分的代码。
更一般地,预处理器用于在不同条件下对源代码进行不同的考虑。
更一般来说,预处理器用于为不同的条件生成不同的源代码。
在这种情况下,预处理器的范围仅在编译/构建代码之前 ... 不是之后,您已经构建了代码,并获得了可执行文件/ .cod / ...等。文件



阅读前一行 T H E S E 链接;虽然这些都是关于C-Preprocessors,但基本也适用于这里。



假设你的代码如下:

  // START OF CODE 
//#preprocess
//这是代码的第二行
// ...
//#ifdef OS_5
import net.rim.device.api.ui.component.AutoCompleteField;
//#else
//如果需要,不导入AutoCompleteField并导入其他东西
//#endif

// ...
// ... //一些更多的代码
// ...

//#ifdef OS_5
// ...
// ...
//使用AutoCompleteField的代码
// ...
// ...
//#else
// ...
/ / ...
//自己实现AutoCompleteField的代码另外一种方式你自己
// ...
// ...

// ...
// ... //更多代码
// ...
// END OF CODE

如果您使用预处理程序'OS_5'构建代码(JDE,Eclipse或使用Ant),您无论使用什么工具c $ c>然后(如果您的工具可以理解预处理器),将生成以下代码:

  // START OF CODE 
//这是代码的第二行
// ...
import net.rim.device.api.ui.component.AutoCompleteField;

// ...
// ... //更多代码
// ...

// ...
// ...
//使用AutoCompleteField的代码
// ...
// ...

// ...
// ... //更多代码
// ...
// END OF CODE

$将使用上述代码生成b
$ b

.cod 文件。而这个 .cod 文件不能在BB OS版本小于5.0的情况下运行,因为 AutoCompleteField 由OS 5支持。



如果您构建而不使用预处理器'OS_5'或其他预处理器
然后将生成以下代码:

  // START OF CODE 
//这是代码的第二行
// ...
//如果需要,不导入AutoCompleteField并导入其他东西

// ...
// ... //更多代码
// ...


// ...
// ...
//自动实现AutoCompleteField的代码另外一种方法由
// ...
// ...

// ...
//。 .. //一些更多的代码
// ...
// END OF CODE

.cod 文件将使用上述代码生成,这将是一个不同的 .cod 文件比上一个。



现在,如果你想准备一个单一的BUILD 并部署成功,不同的BB操作系统支持的设备,那么你有到删除依赖关系同时编码,即仅使用所有操作系统版本(4.6,5.0 ...等)支持的API类。但是有些情况下有时候会出现困难,因为您可能需要编写自己的代码才能实现某些功能。



为不同的操作系统准备不同的构建更容易 - 为此,您当然可以使用预处理程序。






恐怕可能我已经解释了一件容易的事情以非常复杂的方式。


I have a project which needs to be used in 4.6 and 5.0 versions of blackberry. I have run same code in both the 4.6 and 5.0 versions with some preprocessor directives attached to the code (#ifndef statements which i need to use for 5.0 as facebook sdk is not supported in 4.6 version) I have 2 .cod files ( one for 4.6 and other for 5.0) they work as needed in their respective simulators.

But, when i load the .cod file of 4.6 into 5.0 ... (it treats it as the code inside preprocessor as comment) and when i do it viceversa

ie from 5.0 into 4.6 ... it says ... projectname-1.cod not found .

A similar question is been posted here too check out where a comment on bbtool says it can be possible One build for two different versions (4.6,4.7 and 5.0+above) in blackberry

解决方案

Using preprocessor is not the way to make A SINGLE BUILD for different BB OS Versions (No matter what tool you use to prepare the build).

Preprocessors are used just to remove/add particular portion of code based on provided conditions before compiling/building the entire code. More generally, preprocessors are used to consider the source code differently for different conditions. More more generally, preprocessors are used to produce different source codes for different conditions. In such a case the scope of preprocessors is only before compiling/building the code... not after you have build the code and got the executable/.cod/...etc. file

Read first few lines of T H E S E links; though these are about C-Preprocessors, but the basic is also applicable here.

Suppose your code is as following:

// START OF CODE
//#preprocess
// this is the second line of the code
//...
//#ifdef OS_5
import net.rim.device.api.ui.component.AutoCompleteField;
//#else
//don't import AutoCompleteField and import something else if needed
//#endif

//...
//... // some more codes
//...

//#ifdef OS_5
//...
//...
// Codes for using AutoCompleteField
//...
//...
//#else
//...
//...
// Codes for implementing AutoCompleteField another way by yourself
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

It doesn't matter what tool you use to build your code (JDE, Eclipse or using Ant), if you build with the preprocessor 'OS_5' then (if your tool can understand preprocessors) the following code will be generated :

// START OF CODE
// this is the second line of the code
//...
import net.rim.device.api.ui.component.AutoCompleteField;

//...
//... // some more codes
//...

//...
//...
// Codes for using AutoCompleteField
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

and the .cod file will be generated with the above code. And this .cod file will not run on BB OS Versions less than 5.0 because AutoCompleteField is supported from OS 5.

And if you build without the preprocessor 'OS_5' or other preprocessors then the following code will be generated:

// START OF CODE
// this is the second line of the code
//...
//don't import AutoCompleteField and import something else if needed

//...
//... // some more codes
//...


//...
//...
// Codes for implementing AutoCompleteField another way by yourself
//...
//...

//...
//... // some more codes
//...
 // END OF CODE

and the .cod file will be generated using the above code, and This is going to be a different .cod file than the previous one.

Now if you want to prepare A SINGLE BUILD and deploy it successfully different BB OS supported devices, then you have to remove dependencies while coding, i.e. use only those API-classes that are supported by all the OS versions (4.6, 5.0... and others if you want). But it's very difficult sometimes for some cases, because you may have to write your own codes for implementing some features.

It's easier to prepare different builds for different OS --- and on that purpose you can of course use preprocessors..


I'm afraid may be I have explained an easy thing in a very complex way.

这篇关于当使用预处理器时,哪个构建被考虑使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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