VS2022在Ubuntu调试Boost多索引容器时崩溃报错
问题描述
- 系统环境:Ubuntu 22.04,使用Visual Studio 2022社区版开发,编译器为GCC 11.4,构建工具采用CMake
- Boost通过系统仓库安装,基于Boost多索引容器创建了一个简单项目
- 问题现象:单步调试涉及Boost的代码时,弹出错误窗口提示
Undefined command: "d_index_node<boost",随后Visual Studio挂起;若不设置断点直接启动调试,或调试未使用Boost的代码,则无此错误 - 定位问题:代码行
auto oneElementIterator = hashedOrderIndex.find(24);是引发问题的原因,包含该行时调试功能失效
项目代码
#include <boost/multi_index_container.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/sequenced_index.hpp> #include <boost/multi_index/random_access_index.hpp> #include <boost/multi_index/identity.hpp> #include <boost/multi_index/member.hpp> #include <boost/lambda/lambda.hpp> #include <iostream> #include <ctime> #include <string> using namespace boost::lambda; using namespace ::boost; using namespace ::boost::multi_index; using namespace std; //from boost doc struct employee { int id; std::string name; int ssnumber; employee(int id, const std::string& name, int ssnumber) : id(id), name(name), ssnumber(ssnumber) {} bool operator<(const employee& e)const { return id < e.id; } }; typedef multi_index_container< employee, indexed_by< // sort by employee::operator< ordered_unique<boost::multi_index::identity<employee>>, // sort by less<string> on name ordered_non_unique <boost::multi_index::tag<struct employeeByIdNonUniq>, member<employee, std::string, &employee::name>>, // sort by less<int> on ssnumber ordered_unique <boost::multi_index::tag<struct employeeByIdUniq>, member<employee, int, &employee::ssnumber>> > > employee_set; struct comp_id { // compare an ID and an employee bool operator()(int x, const employee& e2)const { return x < e2.id; } // compare an employee and an ID bool operator()(const employee& e1, int x)const { return e1.id < x; } }; int main() { employee_set es; for (int i = 0; i < 500; i++) { employee emp(i, "Name" + to_string(i), 3105 + i); es.insert(emp); } auto& hashedOrderIndex = es.get<employeeByIdUniq>(); //if build with this line debugging does not work auto oneElementIterator = hashedOrderIndex.find(24); employee_set::iterator p0 = es.lower_bound(5, comp_id()); employee_set::iterator p1 = es.upper_bound(10, comp_id()); while (p0 != p1) { string name = (*p0).name; std::cout << to_string((*p0).id) << " " << name << std::endl; p0++; } return 0; }
CMake配置
cmake_minimum_required(VERSION 3.15) project ("boost_multiindex_test") set(CMAKE_CXX_STANDARD 20) list(APPEND CMAKE_PREFIX_PATH "/home/user123/boost_1.86_build/" ) FIND_PACKAGE( Boost 1.86 COMPONENTS program_options REQUIRED ) message ( "Status ${Boost_LIBRARIES}, include dir ${Boost_INCLUDE_DIRS}, boost root ${BOOST_ROOT}" ) set(SOURCE_FILES "boost_example.cpp" ) include_directories ( ./ ${Boost_INCLUDE_DIRS} ) add_executable (boost_example ${SOURCE_FILES} )
内容的提问来源于stack exchange,提问作者Vit123
相关产品推荐
相关产品推荐

