通过 Visual Studio 使用 boost 测试

发布于 2024-08-18 15:31:36 字数 536 浏览 17 评论 0原文

我正在尝试使用 Boost Test 在我的代码中添加一些急需的单元测试。但是我似乎无法让它工作。现在我有以下代码

#include <Drawing.h>
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_MODULE DrawingModelTests
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(DrawingModelTests)

BOOST_AUTO_TEST_CASE ( DrawingConstructorTest)
{
    Drawing * drawing = new Drawing;

    delete drawing;
}

BOOST_AUTO_TEST_SUITE_END()

据我所知,我不需要放置 main 或任何东西,因为 boost 会自己处理它。然而,Visual Studio 不断给我一个“必须定义入口点”错误。我需要手动添加静态库的链接什么的吗?我正在编译为标准 .exe 控制台应用程序。

I am trying to use Boost Test to add some much needed unit tests to my code. However I can't seem to get it to work. Right now I have the following code

#include <Drawing.h>
#define BOOST_AUTO_TEST_MAIN
#define BOOST_TEST_MODULE DrawingModelTests
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(DrawingModelTests)

BOOST_AUTO_TEST_CASE ( DrawingConstructorTest)
{
    Drawing * drawing = new Drawing;

    delete drawing;
}

BOOST_AUTO_TEST_SUITE_END()

From what I understand I don't need to put a main or anything since boost will take care of it himself. However Visual Studio keep giving me a "entry point must be defined" error. Do I need to manually add a link to the static library or something? I am compiling as a standard .exe console application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

薄荷梦 2024-08-25 15:31:36

将 /SUBSYSTEM:CONSOLE 添加到链接器标志。在项目设置中,位于 Linker->System 页面。您可以将 boost 用作动态或静态库。

Add /SUBSYSTEM:CONSOLE to the linker flags. In the project settings, this is on the Linker->System page. You can use boost as either dynamic or static library.

云醉月微眠 2024-08-25 15:31:36

我在VS2010中遇到了这个问题,解决方案是设置“配置属性->”链接器->高级->项目的“入口点”到“主要”。

I had this problem with VS2010 and the solution was to set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'main' for the project.

微暖i 2024-08-25 15:31:36

我的代码类似,并且工作正常。我能看到的唯一区别是我根本没有定义 BOOST_AUTO_TEST_MAIN 。据我所知,BOOST_TEST_MODULE 告诉它在哪里定义main

My code is similar, and works fine. The only difference I can see is that I don't define BOOST_AUTO_TEST_MAIN at all. BOOST_TEST_MODULE tells it where to define main, as far as I'm aware.

小兔几 2024-08-25 15:31:36

我设置了“配置属性->”链接器->高级-> “入口点”到“mainCRTStartup”,这对我来说很有效。 (在我的特定构建配置中,我静态链接 boost 库)。

I set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'mainCRTStartup', which does the trick for me. (In my particular build configuration I'm statically linking boost libraries).

帅冕 2024-08-25 15:31:36

最后,使其工作的方法是使用 boost.test 作为动态库而不是静态库。

In the end, the way to make it work was to use boost.test as a dynamic library instead of a static library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文