[英]How to use environment variable in #import c++ command?
nowadays I have this piece of code: 如今,我有这段代码:
#import "C:\Users\Public\SoundLog\DLLs\ForPython\SoundLogDLL.tlb" named_guids
but I want to substitute the C:\\Users\\Public part by the %PUBLIC% environment variable. 但我想用%PUBLIC%环境变量代替C:\\ Users \\ Public部分。
How can I do this ? 我怎样才能做到这一点 ?
我认为您最好的选择是在代码中编写#import "SoundLogDLL.tlb" named_guids
,然后使用INCLUDE
环境变量, /I
命令行开关切换到编译器,或使用Additional Include Directories
IDE选项来指向正确方向的编译器。
Not sure you can do that. 不确定您可以这样做。 You may either generate the file during a pre compile build step, or you can use the angle include
#import <filename> <attrs>
and have the location of it in your PATH. 您可以在预编译构建步骤中生成文件,也可以使用角度include
#import <filename> <attrs>
并将其位置放在PATH中。 See MSDN for more info, specifically Search Order for filename. 有关更多信息,请参见MSDN ,尤其是文件名的搜索顺序。
Using a hard coded path in your code is never a good idea. 在代码中使用硬编码路径绝不是一个好主意。
I recommend using a relative path and keeping your type library under the same folder structure as your code. 我建议使用相对路径,并使类型库与代码位于相同的文件夹结构下。
Then doing something like this: 然后做这样的事情:
#import <SoundLogDLL.tlb> named_guids #import <SoundLogDLL.tlb> named_guids
It would be wise to store your projects in a common folder so that you can use relative paths. 将项目存储在公共文件夹中是明智的,这样您就可以使用相对路径。 The #import directive also searches files in the same folders where it looks for #include files.
#import指令还会在查找#include文件的文件夹中搜索文件。 In the IDE, you can add them with Project + Properties, C/C++, General, Additional Include Directories.
在IDE中,您可以使用“项目+属性”,“ C / C ++”,“常规”,“附加包含目录”来添加它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.