c++-cli - 将 BoostTest 与 C++/CLI 一起使用 : possible or not?

标签 c++-cli boost-test

我有一个包含程序代码(模型)的 Visual Studio 项目。我已经创建了另一个项目来将增强测试放入其中。

问题是我无法让它工作。

我可以在项目中单独使用 boost 测试,但是一旦我想链接(引用等)到第一个项目(我想在其上运行测试的项目),boost 测试项目就不会编译:

1>E:\boost_1_53_0\boost/detail/interlocked.hpp(99): warning C4164: '_InterlockedExchange' : fonction intrinsèque non déclarée
1>E:\boost_1_53_0\boost/detail/interlocked.hpp(100): warning C4164: '_InterlockedExchangeAdd' : fonction intrinsèque non déclarée
1>E:\boost_1_53_0\boost/smart_ptr/detail/spinlock_w32.hpp(62): error C3861: '_InterlockedExchange' : identificateur introuvable

我读了there你不能

your code is not C++ but "C++ CLI" and thus you cant use boost. C++ does not have a System namespace. In each .cpp file you can either use C++/CLI (and therefore the System namespace) OR boost. If you want to use the System namespace you have to enable the "Common Langauge Runtime Support", for boost you have to disable it

>> 谁能确认不能将 Boost 与 C++/CLI 程序一起使用?

最佳答案

是的,这是可能的。

首先,您必须将 C++/CLI 项目更改为/clr(/clr:pure 或/clr:safe 将不起作用)。这允许您的项目以混合模式运行,即同时运行 native C++ 和托管代码。
Read more on msdn.microsoft.com

为 Visual Studio 设置 Boost.Test(将路径添加到 Boost 的 .h,并在链接器中添加 .lib 路径;您可能必须编译 Boost,因为在某些情况下它不是“仅 header ”);这里有一个很好的教程itee.uq.edu.au

就是这样,您可以编写和编译您的测试。

但是,由于 C++/CLI 代码和 Boost 的编译(链接,最有可能)过程中的错误,我无法将 Boost 测试放在不同的项目中;所以我不得不将单元测试放在程序本身的代码中(尽管在单独的 .cpp 文件中,这是一个可接受的解决方案)。

关于c++-cli - 将 BoostTest 与 C++/CLI 一起使用 : possible or not?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16194589/

相关文章:

c++ - CoInitializeEx 用于 boost::test::unit_test

c++ - 尝试使用 boost.Test 捕获 block

c++ - 编写可以访问私有(private)/ protected 状态的单元测试

c++ - 如何在 Visual Studio 2010 c++ 项目中使用 System.Net 命名空间?

eclipse - C++ Boost 测试、包结构和 Eclipse 项目设置

c - 使用 hashmap 从数组中删除重复条目

c++ - ^ 在 bool GetDeviceInformation(String ^ port, LibCECConfiguration ^configuration, uint32_t timeoutMs) 中是什么意思

c++ - 如何将 Boost.Test 输出记录到 HRF 中的标准输出和 XML 中的文件?

c++ - 我怎样才能 boost::bind 到传递并返回 std::string 的托管类的成员?

c# - 在 .NET 中,即使对象的构造函数从未运行过,终结器也可以运行吗?