gpt4 book ai didi

Boost 错误,编译 xtime.hpp 时遇到问题

转载 作者:行者123 更新时间:2023-12-04 09:31:31 25 4
gpt4 key购买 nike

我一直在使用 Boost 处理 C++ 项目,并且在两次编译之间,我必须升级了 boost 中的某些东西而没有任何意义,因为现在 Boost 依赖项将无法编译:

In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah.h:4,
from bluh.h:3,
from bleh/main.cpp:4:
/usr/include/boost/thread/xtime.hpp:23:5: error: expected identifier before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected '}' before numeric constant
/usr/include/boost/thread/xtime.hpp:23:5: error: expected unqualified-id before numeric constant
/usr/include/boost/thread/xtime.hpp:46:14: error: expected type-specifier before 'system_time'
In file included from /usr/include/boost/thread/pthread/mutex.hpp:14:0,
from /usr/include/boost/thread/mutex.hpp:16,
from /usr/include/boost/thread/pthread/thread_data.hpp:12,
from /usr/include/boost/thread/thread.hpp:17,
from /usr/include/boost/thread.hpp:13,
from /blah,
from /bleh,(changed these names, obviously)
from /bluh /main.cpp:4:
/usr/include/boost/thread/xtime.hpp: In function 'int xtime_get(xtime*, int)':
/usr/include/boost/thread/xtime.hpp:73:40: error: 'get_system_time' was not declared in this scope
/usr/include/boost/thread/xtime.hpp:73:40: note: suggested alternative:
/usr/include/boost/thread/thread_time.hpp:19:24: note: 'boost::get_system_time'
/usr/include/boost/thread/xtime.hpp: At global scope:
/usr/include/boost/thread/xtime.hpp:88:1: error: expected declaration before '}' token
make[2]: *** [CMakeFiles/edge_based_tracker.dir/main.o] Error 1
make[1]: *** [CMakeFiles/edge_based_tracker.dir/all] Error 2
make: *** [all] Error 2

有任何想法吗?我尝试将 TIME_UTC 更改为 TIME_UTC_,因为这是在另一个站点上向我推荐的,但这似乎没有帮助。

编辑:Boost 版本是版本:1.48.0.2。我在下面附上了 xtime:
// Copyright (C) 2001-2003
// William E. Kempf
// Copyright (C) 2007-8 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_XTIME_WEK070601_HPP
#define BOOST_XTIME_WEK070601_HPP

#include <boost/thread/detail/config.hpp>

#include <boost/cstdint.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>

#include <boost/config/abi_prefix.hpp>

namespace boost {

enum xtime_clock_types
{
TIME_UTC=1 //LINE 23
// TIME_TAI,
// TIME_MONOTONIC,
// TIME_PROCESS,
// TIME_THREAD,
// TIME_LOCAL,
// TIME_SYNC,
// TIME_RESOLUTION
};

struct xtime
{
#if defined(BOOST_NO_INT64_T)
typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
#else
typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
#endif

typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND

xtime_sec_t sec;
xtime_nsec_t nsec;

operator system_time() const
{
return boost::posix_time::from_time_t(0)+
boost::posix_time::seconds(static_cast<long>(sec))+
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
boost::posix_time::nanoseconds(nsec);
#else
boost::posix_time::microseconds((nsec+500)/1000);
#endif
}

};

inline xtime get_xtime(boost::system_time const& abs_time)
{
xtime res;
boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);

res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
return res;
}

inline int xtime_get(struct xtime* xtp, int clock_type)
{
if (clock_type == TIME_UTC)
{
*xtp=get_xtime(get_system_time());
return clock_type;
}
return 0;
}


inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
{
if (xt1.sec == xt2.sec)
return (int)(xt1.nsec - xt2.nsec);
else
return (xt1.sec > xt2.sec) ? 1 : -1;
}

} // namespace boost

#include <boost/config/abi_suffix.hpp>

#endif //BOOST_XTIME_WEK070601_HPP

编辑:为了清楚起见,代码在导入 boost/thread.hpp 时失败

最佳答案

对于那些遇到相同问题并努力在此处找到解决方案的人。
源自 noodlebox 的链接 (https://svn.boost.org/trac/boost/ticket/6940):

您可以编辑/usr/include/boost/thread/xtime.hpp (或 xtime.hpp 所在的任何位置)
并更改所有出现的 TIME_UTC TIME_UTC_ - 大概在第 23 行和第 71 行左右。

sed -i 's/TIME_UTC/TIME_UTC_/g' /usr/include/boost/thread/xtime.hpp

关于Boost 错误,编译 xtime.hpp 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17599377/

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