简体   繁体   English

在64位Windows上进行Boost.Test

[英]Boost.Test on 64-bit Windows

I'm trying to utilize Boost.Test in Visual Studio 2010, and I'm having some trouble getting it to work. 我正在尝试在Visual Studio 2010中使用Boost.Test,而我在使其工作时遇到了一些麻烦。 Here's the source: 这是来源:

#include "stdafx.hpp"

#define BOOST_TEST_MODULE (main)
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(morphology)
{
    BOOST_CHECK(true);
}

stdafx.hpp is literally empty. stdafx.hpp实际上是空的。 The project was created as an empty C++ project, set to build an application, with directories set up to point to boost headers and libs. 该项目是作为一个空的C ++项目创建的,设置为构建一个应用程序,目录设置为指向boost头和libs。 I'm using /entry to point to the main function provided by Boost.Test. 我正在使用/ entry来指向Boost.Test提供的main功能。

There seem to be a couple of things going on. 似乎有一些事情正在发生。 Firstly, at build time, the linker reports warnings over all the objects in the test lib, claiming ".CRT section exists; there may be unhandled static initializers or terminators": 首先,在构建时,链接器报告测试库中所有对象的警告,声称“.CRT部分存在;可能存在未处理的静态初始化器或终结器”:

1>msvcprtd.lib(locale0_implib.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>morphology.obj : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(unit_test_main.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(framework.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(test_tools.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(unit_test_log.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(unit_test_suite.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(results_reporter.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(results_collector.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(unit_test_parameters.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(unit_test_monitor.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(debug.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(progress_monitor.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(plain_report_formatter.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>libboost_unit_test_framework-vc100-mt-gd-1_49.lib(xml_report_formatter.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

Art runtime, the test application crashes somewhere in the Boost.Test library under the call tree of the main provided by Boost.Test: 艺术运行时,测试应用程序在Boost.Test库提供的main调用树下的某个Boost.Test库中崩溃:

>   Pentachoron.Test.exe!std::list<boost::shared_ptr<boost::runtime::cla::parameter>,std::allocator<boost::shared_ptr<boost::runtime::cla::parameter> > >::begin()  Line 787 + 0x13 bytes   C++
    Pentachoron.Test.exe!boost::unit_test::for_each::begin<std::list<boost::shared_ptr<boost::runtime::cla::parameter>,std::allocator<boost::shared_ptr<boost::runtime::cla::parameter> > > >(const std::list<boost::shared_ptr<boost::runtime::cla::parameter>,std::allocator<boost::shared_ptr<boost::runtime::cla::parameter> > > & t, boost::mpl::bool_<1> __formal)  Line 107 + 0xf bytes  C++
    Pentachoron.Test.exe!boost::runtime::cla::parser::operator[](boost::unit_test::basic_cstring<char const > string_id)  Line 169 + 0x41 bytes C++
    Pentachoron.Test.exe!boost::unit_test::runtime_config::`anonymous namespace'::retrieve_parameter<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >(boost::unit_test::basic_cstring<char const > parameter_name, const boost::runtime::cla::parser & s_cla_parser, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & default_value, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & optional_value)  Line 216 + 0x34 bytes  C++
    Pentachoron.Test.exe!boost::unit_test::runtime_config::report_sink()  Line 470 + 0x8b bytes C++
    Pentachoron.Test.exe!boost::unit_test::results_reporter::`anonymous namespace'::results_reporter_impl::results_reporter_impl()  Line 59 + 0x31 bytes    C++
    Pentachoron.Test.exe!boost::unit_test::results_reporter::`anonymous namespace'::s_rr_impl()  Line 91 + 0x35 bytes   C++
    Pentachoron.Test.exe!boost::unit_test::results_reporter::get_stream()  Line 120 + 0x5 bytes C++
    Pentachoron.Test.exe!`boost::unit_test::unit_test_main'::`1'::catch$3()  Line 207 + 0x5 bytes   C++
    msvcr100d.dll!_CallSettingFrame()  Line 44  Asm
    msvcr100d.dll!__CxxCallCatchBlock(_EXCEPTION_RECORD * pExcept)  Line 1337 + 0x15 bytes  C++
    ntdll.dll!0000000077c50c21()    
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
    Pentachoron.Test.exe!boost::unit_test::unit_test_main(boost::unit_test::test_suite * (int, char * *)* init_func, int argc, char * * argv)  Line 179 C++
    Pentachoron.Test.exe!main(int argc, char * * argv)  Line 238    C++
    kernel32.dll!000000007753652d()     
    ntdll.dll!0000000077c2c521()    

Please....someone tell me there's just a compiler flag I didn't set, or something stupid like that... 请....有人告诉我,这里只有一个我没有设置的编译器标志,或者像那样愚蠢......

Alright, I got it figured out. 好吧,我明白了。 The problem was caused by me setting /entry to point directly to main, which bypasses all the static object constructors and runtime intialization. 问题是由于我将/ entry设置为直接指向main,它绕过了所有静态对象构造函数和运行时初始化。 Once I set the /subsystem:console option and just let the compiler set up the runtime correctly and call the main function supplied by Boost.Test, it worked as expected. 一旦我设置了/subsystem:console选项并让编译器正确设置运行时并调用Boost.Test提供的main函数,它就按预期工作了。

What a hassle. 多么麻烦。

The /subsystem:console parameter is for the MSVC linker. /subsystem:console参数用于MSVC链接器。 To configure this, right-click your project, go to Linker | 要配置它,请右键单击您的项目,转到Linker | Command Line , and add /subsystem:console to Additional Options at the bottom of the dialog. Command Line ,并在对话框底部添加/subsystem:consoleAdditional Options (VS2013) (VS2013)

I use Boost.Test on x64 with no problems. 我在x64上使用Boost.Test没有问题。

Can you verify that the C runtime libraries you are linking in your application matches the one used by Boost? 您能否验证您在应用程序中链接的C运行时库是否与Boost使用的C运行时库匹配? Boost appears to be using /MDd according to your linker output. Boost似乎根据您的链接器输出使用/ MDd。 (See MSDN ). (参见MSDN )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM