![](/img/trans.png)
[英]Microsoft Visual Studio 2015 doesn't has Windows Driver option?
[英]Can't build Google Test with Visual Studio 2015 and Clang 3.7 with Microsoft CodeGen
使用VS 2015及其新的内置clang工具集/项目模板,我无法成功构建Google Test。 我收到以下错误:
Error use of undeclared identifier 'chdir'; did you mean '_chdir'?
Error use of undeclared identifier 'fdopen'
Error use of undeclared identifier 'read'
Error use of undeclared identifier 'write'
Error use of undeclared identifier 'close'
Error use of undeclared identifier 'O_RDONLY'
Error use of undeclared identifier 'O_APPEND'
Error use of undeclared identifier 'dup'; did you mean '_dup'?
Error use of undeclared identifier 'creat'; did you mean '_creat'?
我注意到这些声明中的大多数都在这些ANSI检查块中:
#if !__STDC__
...
#endif
是否有项目设置或我可以更改以使这些方法解决?
我遇到了与chdir和freopen类似的问题。
我将发布我采取的步骤,以获得googletest并运行VS2015和Clang。
这将安装最新版本的clang(在编写v3.9时)。 请注意,这是一个快照构建,而不是正式版本。
如果您不喜欢快照构建,可以尝试最新版本。 我没有测试它。 我只是喜欢拥有最新的工具,特别是当它们像LLVM / Clang一样快节奏时。
Properties
- > General
- > Platform Tools
- > LLVM-vs2014
(及更多)(切换到LLVM-vs2014
) 我知道你要求使用Microsoft CodeGen的Clang 3.7。 你必须自己决定。
另外,我不想对我没写或不知道的代码应用一些修复/更改。 由于这对我来说很好,我没有进一步调查这个问题。
此时它可能已经适合您。 接下来的步骤描述了构建googletest库并将include目录添加到项目中。
从github获取googletest。 https://github.com/google/googletest
运行cmake-gui并配置googletest以便能够构建。
生成器:Visual Studio 14 2015 Win64(我只使用64位,你也可以尝试32位)
来自llvm文档
(没有链接,因为没有足够的声誉:clang.llvm.org/docs/MSVCCompatibility.html):首先,Clang尝试与ABI兼容,这意味着Clang编译的代码应该能够成功地链接到MSVC编译的代码。
源代码在哪里:(例如C:\\libs\\googletest\\googletest
)
(因为顶级目录中也有googlemock)
在哪里构建二进制文件:(例如C:\\libs\\googletest\\build
)
BUILD_SHARED_LIBS
(如果需要,可以构建共享库) CMAKE_CONFIGURATION_TYPES
:调试和发布(如果您愿意,可以选择其他人) CMAKE_INSTALL_PREFIX
(例如C:\\libs\\googletest\\install
) Python 2.7是由cmake发现的,即使我很确定它没有必要。
按Configure and Generate。
生成解决方案文件后,转到上面指定的目录(构建二进制文件的位置,例如C:\\libs\\googletest\\build
)并打开解决方案gtest.sln。
选择Debug solution configuration并右键单击ALL_BUILD和Build。 完成后,右键单击“安装”和“构建”。 这将创建前面指定的文件夹。
CMAKE_INSTALL_PREFIX
(例如C:\\libs\\googletest\\install
)在那里您可能想要更改libs名称并添加* d.lib以防止文件被覆盖,并将其作为调试版本的指示符。
重复发布解决方案配置的步骤。 在CMAKE_INSTALL_PREFIX
(例如C:\\libs\\googletest\\install
)中,您应该找到一个包含目录和一个lib目录。
在属性 - > VC ++目录下的项目中添加包含目录。 CMAKE_INSTALL_PREFIX<b>\\include</b>
(例如C:\\libs\\googletest\\install<b>\\include</b>
)
在属性 - > VC ++目录下的项目中添加库目录。 CMAKE_INSTALL_PREFIX \\ lib (例如C:\\ libs \\ googletest \\ install \\ lib )
在Properties
- > Linker
- > Input
- > Additional Dependencies
(gtest.lib / gtestd.lib,具体取决于您的配置)下
之后,我能够构建并运行我的测试。
由于使用较新的LLVM / Clang进行调试时出错,我花了一些时间使用VS2015,Clang 3.7和googletest。
我在其他答案中提到了编译googletest库。 然后切换到“Clang 3.7 with Microsoft CodeGen(v140_clang_3_7)”来构建我的googletest项目。
错误示例输出:
.... gtest / internal / gtest-port.h(2384,35):错误:使用未声明的标识符'close'
inline int Close(int fd){return close(fd); }
在Microsoft的文档中,您可以找到:
使用fdopen的示例
fdopen:不推荐使用此POSIX函数。 请改用ISO C ++ conformant _fdopen。
https://msdn.microsoft.com/en-us/library/ms235351.aspx
这与相当多的功能相同。
只需谷歌搜索“visual studio xxx”,其中xxx是fdopen或chdir。 您应该获得文档的链接,您可以在其中找到新方法。 (通常是名称前面的下划线。)
一旦你知道要使用什么,转到错误(使用VS输出去那里),这里是gtest-port.h(2384,35)。
在这里进行更改
...返回关闭(fd);
至
... return _ close(fd);
等等。
之后,我的测试像往常一样工作。 不得不摆脱一些警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.