Use of deleted function error with Boost

本文介绍了一种在使用较新版本的C++编译器时遇到的Boost库兼容性错误,并提供了两种解决方案:一是回退到旧版本的C++编译器;二是升级Boost库版本。作者选择了后者并成功解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://choorucode.com/2013/12/27/use-of-deleted-function-error-with-boost/


Problem

I was compiling C++ code that uses the Boost library when the compiler threw out this mysterious error:

/usr/include/boost/thread/pthread/thread_data.hpp: In constructor ‘boost::detail::tss_data_node::tss_data_node(boost::shared_ptr, void*)’:
/usr/include/boost/thread/pthread/thread_data.hpp:36:41: error: use of deleted function ‘boost::shared_ptr::shared_ptr(const boost::shared_ptr&)’
                 func(func_),value(value_)

Solution

This type of error typically occurs when there is a feature mismatch between the C++ compiler and the library code. In this case, I was using the Boost library version 1.48.0, which is from Ubuntu 12.04. However, I was using a newer version of the g++ compiler since the code used C++11 features. The version that is in Ubuntu was 4.6, while I using a more recent version 4.8 compiler.

One solution is to go back and use an older version of the C++ compiler. The other solution is to upgrade the Boost library to a more recent version. I chose the second solution and upgraded Boost to version 1.54 and the code compiled without errors.

8Return<void> CameraDeviceSession::configureStreams( 1029 const StreamConfiguration& requestedConfiguration, 1030 ICameraDeviceSession::configureStreams_cb _hidl_cb) { 1031 Status status = initStatus(); 1032 HalStreamConfiguration outStreams; 1033 1034 // hold the inflight lock for entire configureStreams scope since there must not be any 1035 // inflight request/results during stream configuration. 1. lock_acquire: 调用 Autolock 将获取锁 this->mInflightLock.mMutex。[显示详情] 1036 Mutex::Autolock _l(mInflightLock); 2. 条件 !this->mInflightBuffers.empty(),使用了 false 分支。 1037 if (!mInflightBuffers.empty()) { 1038 ALOGE("%s: trying to configureStreams while there are still %zu inflight buffers!", 1039 __FUNCTION__, mInflightBuffers.size()); 1040 _hidl_cb(Status::INTERNAL_ERROR, outStreams); 1041 return Void(); 1042 } 1043 3. 条件 !this->mInflightAETriggerOverrides.empty(),使用了 false 分支。 1044 if (!mInflightAETriggerOverrides.empty()) { 1045 ALOGE("%s: trying to configureStreams while there are still %zu inflight" 1046 " trigger overrides!", __FUNCTION__, 1047 mInflightAETriggerOverrides.size()); 1048 _hidl_cb(Status::INTERNAL_ERROR, outStreams); 1049 return Void(); 1050 } 1051 4. 条件 !this->mInflightRawBoostPresent.empty(),使用了 false 分支。 1052 if (!mInflightRawBoostPresent.empty()) { 1053 ALOGE("%s: trying to configureStreams while there are still %zu inflight" 1054 " boost overrides!", __FUNCTION__, 1055 mInflightRawBoostPresent.size()); 1056 _hidl_cb(Status::INTERNAL_ERROR, outStreams); 1057 return Void(); 1058 } 1059 5. 条件 status != OK,使用了 false 分支。 1060 if (status != Status::OK) { 1061 _hidl_cb(status, outStreams); 1062 return Void(); 1063 } 1064 1065 camera3_stream_configuration_t stream_list{}; 1066 hidl_vec<camera3_stream_t*> streams; CID 174615: (#1 of 1): 持有锁时等待 (SLEEP) 6. sleep: 对 preProcessConfigurationLocked 的调用可能在持有锁 this->mInflightLock.mMutex 的情况下睡眠。[显示详情] 1067 if (!preProcessConfigurationLocked(requestedConfiguration, &stream_list, &streams)) { 1068 _hidl_cb(Status::INTERNAL_ERROR, outStreams); 1069 return Void(); 1070 } 1071 1072 ATRACE_BEGIN("camera3->configure_streams"); 1073 status_t ret = mDevice->ops->configure_streams(mDevice, &stream_list); 1074 ATRACE_END(); 1075 1076 // In case Hal returns error most likely it was not able to release 1077 // the corresponding resources of the deleted streams. 1078 if (ret == OK) { 1079 postProcessConfigurationLocked(requestedConfiguration); 1080 } else { 1081 postProcessConfigurationFailureLocked(requestedConfiguration); 1082 } 1083 1084 if (ret == -EINVAL) { 1085 status = Status::ILLEGAL_ARGUMENT; 1086 } else if (ret != OK) { 1087 status = Status::INTERNAL_ERROR; 1088 } else { 1089 convertToHidl(stream_list, &outStreams); 1090 mFirstRequest = true; 1091 } 1092 1093 _hidl_cb(status, outStreams); 1094 return Void(); 1095}
最新发布
07-27
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值