通过 Visual Studio 使用 boost 测试
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将 /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.
我在VS2010中遇到了这个问题,解决方案是设置“配置属性->”链接器->高级->项目的“入口点”到“主要”。
I had this problem with VS2010 and the solution was to set 'Configuration Properties -> Linker -> Advanced -> Entry Point' to 'main' for the project.
我的代码类似,并且工作正常。我能看到的唯一区别是我根本没有定义
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 definemain
, as far as I'm aware.我设置了“配置属性->”链接器->高级-> “入口点”到“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).
最后,使其工作的方法是使用 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.