英文:
seperate #define on same project in different solutions
问题
我有一个C++项目,它包含在两个不同的解决方案中。我希望在每个解决方案下,该项目具有不同的#define
常量。有没有办法做到这一点?
我最佳的解决方案是在其中构建不同的项目文件,但其中包含相同的C++代码,但这有点麻烦,我希望有一个更好的解决方案。
英文:
I have a c++ project which is included in two different solutions. I want the project to have different #define
constants under each solution. Is there a way to do it?
My best solution is to build different project file with same c++ codes in it, but its a fuss, and I hope there is a better solution.
答案1
得分: 3
可以有条件地从相应的解决方案文件夹中提取特定于解决方案的属性表。
<ImportGroup Label="PropertySheets">
<Import
Project="$(SolutionDir)SolutionSpecific.props"
Condition="exists('$(SolutionDir)SolutionSpecific.props')"
Label="solution-specific props" />
</ImportGroup>
其中 SolutionSpecific.props
是一个包含宏定义的属性表文件。
英文:
It is possible to conditionally pull solution-specific property sheets from the corresponding solution folder.
<ImportGroup Label="PropertySheets">
<Import
Project="$(SolutionDir)SolutionSpecific.props"
Condition="exists('$(SolutionDir)SolutionSpecific.props')"
Label="solution-specific props" />
</ImportGroup>
where SolutionSpecific.props
is a property sheet file containing macro definition.
答案2
得分: 1
你可以像这样做:
#include <iostream>
#ifdef Proj
#define Bla "Klaf"
#else
#define Bla "Flak"
#endif
int main()
{
std::cout << Bla << '\n';
}
然后通过编译器的命令行参数控制 #ifdef
。
英文:
You can do something like this:
#include <iostream>
#ifdef Proj
#define Bla "Klaf"
#else
#define Bla "Flak"
#endif
int main()
{
std::cout << Bla << '\n';
}
And then control the #ifdef
with a command line argument on your compiler.
Here the one that is compiling with -D Proj
(this flag is for gcc, MSVC uses /D
I think) prints Flak
, and the other prints Klaf
:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论