gpt4 book ai didi

c++ - 64 位 Windows 上的 Boost.Test

转载 作者:可可西里 更新时间:2023-11-01 13:20:16 25 4
gpt4 key购买 nike

我正在尝试在 Visual Studio 2010 中使用 Boost.Test,但在使用它时遇到了一些问题。这是来源:

#include "stdafx.hpp"

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

BOOST_AUTO_TEST_CASE(morphology)
{
BOOST_CHECK(true);
}

stdafx.hpp 实际上是空的。该项目被创建为一个空的 C++ 项目,设置为构建一个应用程序,目录设置为指向 boost 头文件和库。我正在使用/entry 指向 Boost.Test 提供的 main 函数。

似乎有一些事情正在发生。首先,在构建时,链接器报告测试库中所有对象的警告,声称“.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运行时,测试应用在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()

请....有人告诉我我没有设置编译器标志,或者类似的愚蠢...

最佳答案

好的,我明白了。问题是由于我将/entry 设置为直接指向 main,这绕过了所有静态对象构造函数和运行时初始化。一旦我设置了 /subsystem:console 选项并让编译器正确设置运行时并调用 Boost.Test 提供的 main 函数,它就按预期工作了。

真麻烦。

/subsystem:console 参数用于 MSVC 链接器。要配置它,请右键单击您的项目,转到 Linker|Command Line ,然后将 /subsystem:console 添加到 Additional Options 在对话框的底部。 (VS2013)

关于c++ - 64 位 Windows 上的 Boost.Test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9915565/

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