在编译器命令行上传递绝对路径作为预处理器指令
我想通过 /D
定义将 MSVC++ 2008 宏传递到我的程序中,
/D__HOME__="\"$(InputDir)\""
然后在我的程序中我可以这样做
cout << "__HOME__ => " << __HOME__ << endl;
,它应该打印类似的内容
__HOME__ => c:\mySource\Directory
,但它不喜欢反斜杠,所以我实际上得到:
__HOME__ => c:mySourceDirectory
关于如何让它发挥作用有什么想法吗?
更新:我终于得到了这个与托尼下面的答案一起工作,但请注意,$(InputDir)
包含尾随反斜杠,因此实际的宏定义必须有一个额外的反斜杠处理它...黑客如果我见过它!
/D__HOME__="\"$(InputDir)\\""
I'd like to pass a MSVC++ 2008 macro into my program via a /D
define like so
/D__HOME__="\"$(InputDir)\""
then in my program I could do this
cout << "__HOME__ => " << __HOME__ << endl;
which should print something like
__HOME__ => c:\mySource\Directory
but it doesn't like the back slashes so I actually get:
__HOME__ => c:mySourceDirectory
Any thoughts on how I could get this to work?
UPDATE: I finally got this to work with Tony's answer below but note that the $(InputDir)
contains a trailing backslash so the actual macro definition has to have an extra backslash to handle it ... hackery if ever I saw it!
/D__HOME__="\"$(InputDir)\\""
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在宏前面添加字符串化运算符 # 将其转换为字符串。然而,这仅适用于宏。您实际上需要一个双宏才能使其正常工作,否则它只会打印
__HOME__
。顺便说一句,包含双下划线的宏保留给 C++ 中的实现,不应在您的程序中使用。
You can convert your macro to a string by prefixing it with the stringizing operator #. However, this only works in macros. You actually need a double-macro to make it work properly, otherwise it just prints
__HOME__
.Incidentally macros containing double underscores are reserved to the implementation in C++, and should not be used in your program.