gpt4 book ai didi

c++ - boost::program_options 卡在 ARM 上 "sometimes"

转载 作者:可可西里 更新时间:2023-11-01 17:59:41 35 4
gpt4 key购买 nike

目前我正在使用 boost::program_options 来解析 BeagleBoard(基于 ARM 的处理器)上的配置文件。我的程序是多线程的,并链接到 boost 1.45 multithreaded 库。

虽然我的程序在解析配置文件时似乎挂起

namespace po = boost::program_options;
po::options_description desc("Options");
uint32_t option1=0;
std::vector<std::string> optionsString;
std::cout<<"Before adding options"<<std::endl;
desc.add_options()
("option1",
po::value<uint32_t>(&option1), "...")
("finaloption",
po::value<std::vector<std::string> >(&optionsString)->multitoken(), "string of options");
//Never gets here
std::cout<<"After adding options"<<std::endl;
po::variables_map vm;
std::cout<<"Starting program"<<std::endl;

程序在打印出“添加选项之后”之前挂起。如果我通过 gdb 运行该程序,请停止它并进行回溯,它只会显示它在“从不到达此处”评论之前在线。回溯的顶部就在

#0 ??
#1 __lll_lock_wait lowlevellock.c:47
#2 __pthread_mutex_lock pthread_mutex_lock.c:61
#3 in boost::shared_ptr<boost::program_options::option_description>* std::__uninitialized_move_a<boost::shared_ptr<boost::program_options::option_description>*, boost::shared_ptr<boost::program_options::option_description>*, std::allocator<boost::shared_ptr<boost::program_option::option_description> > >(boost::shared_ptr<boost::program_optionns::option_description>*, boost::shared_ptr<boost::program_options::option_description>*, std::allocator<boost::shared_ptr<boost::program_options::option_description> >&) () from /usr/local/lib/libboost_program_options-mt.so.1.45.0
#4 in std::vector<boost::shared_ptr<boost::program_options::option_description>, std::allocator<boost::shared_ptr<boost::program_options::option_description> > >::_M_insert_aux(__gnu_cxx::__normal_iterator<boost::shared_ptr<boost::program_options::option_description>, std::vector<boost::shared_ptr<boost::program_options::option_description>, std::allocator<boost::shared_ptr<boost::program_options::option_description> const&)() from /usr/local/lib/libboost_program_options-mt.so.1.45.0
#5 in boost::program_options::options_description::add(boost::shared_ptr<boost::program_options::option_description>) () from /usr/local/lib/libboost_program_options-mt.so.1.45.0

...(如果你想要更多,请告诉我)

有什么想法吗?该程序在 x86 机器上运行良好

编辑:进一步的信息,这似乎不会在优化关闭时发生(使用 -O2 编译这将相当一致地发生)。

Edit2:进一步的分析表明,在关闭优化的情况下仍然会发生这种情况,-O0。

最佳答案

这可能是与您如何构建 boost 和您的应用程序相关的问题。如果您为 thumb 编译和没有 thumb 编译,则互斥锁实现是不同的。确保使用相同的 thumb 设置编译应用程序和 boost 库。

这是我用来编译 boost 的示例 user-config.jam:

if [ os.name ] = CYGWIN || [ os.name ] = NT
{
HOST_TAG = windows ;
}
else if [ os.name ] = LINUX
{
HOST_TAG = linux-x86 ;
}
else if [ os.name ] = MACOSX
{
HOST_TAG = darwin-x86 ;
}

modules.poke : NO_BZIP2 : 1 ;
modules.poke : NO_GZIP : 1 ;

LIB_ROOT = /home/user/lib ;

NDK_ROOT = $(LIB_ROOT)/android-ndk-r8c ;

LLVM_VERSION = 3.1 ;
LLVM_NAME = llvm-$(LLVM_VERSION) ;
LLVM_TOOLCHAIN_ROOT = $(NDK_ROOT)/toolchains/$(LLVM_NAME) ;
LLVM_TOOLCHAIN_PREBUILT_ROOT = $(LLVM_TOOLCHAIN_ROOT)/prebuilt/$(HOST_TAG) ;
LLVM_TOOLCHAIN_PREFIX = $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/ ;

TOOLCHAIN_VERSION = 4.6 ;
TOOLCHAIN_NAME = arm-linux-androideabi-$(TOOLCHAIN_VERSION) ;
TOOLCHAIN_ROOT = $(NDK_ROOT)/toolchains/$(TOOLCHAIN_NAME) ;
TOOLCHAIN_PREBUILT_ROOT = $(TOOLCHAIN_ROOT)/prebuilt/$(HOST_TAG) ;
TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREBUILT_ROOT)/bin/arm-linux-androideabi- ;

using clang : $(TOOLCHAIN_VERSION) :
$(LLVM_TOOLCHAIN_PREFIX)clang :
<compileflags>"-gcc-toolchain $(TOOLCHAIN_PREBUILT_ROOT)"
<compileflags>"-isystem $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/lib/clang/$(LLVM_VERSION)/include"
<compileflags>"-isysroot $(NDK_ROOT)/platforms/android-9/arch-arm/usr/include"
<compileflags>-std=gnu++11
<compileflags>-stdlib=libc++
<compileflags>-fomit-frame-pointer
<compileflags>-ffast-math
<compileflags>"-target armv7-none-linux-androideabi"
<compileflags>-march=armv7-a
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=neon
<compileflags>-DPAGE_SIZE=sysconf\\(_SC_PAGESIZE\\)
<compileflags>-I$(NDK_ROOT)/boost/include
<compileflags>-I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/include
<compileflags>-I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs//armeabi-v7a/include
<compileflags>-I$(NDK_ROOT)/platforms/android-9/arch-arm/usr/include
<linkflags>-s
<archiver>$(TOOLCHAIN_PREFIX)ar
<ranlib>$(TOOLCHAIN_PREFIX)ranlib
;

请注意,在这个例子中,我没有启用 thumb 进行编译。

关于c++ - boost::program_options 卡在 ARM 上 "sometimes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11953822/

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