gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:45:43 24 4
gpt4 key购买 nike

我有一个包含程序代码(模型)的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com