2013-07-11 251 views
6

我一直在使用Boost编译C++项目,并且在编译之间,我必须升级boost中的某些东西而没有意义,或者因为现在Boost依赖不会编译:Boost错误,编译出错xtime.hpp

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_,因为这是在另一个网站上向我推荐的,但这似乎没有帮助。

编辑:升压版本是版本: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 

编辑:要清楚,代码失败升压/ thread.hpp

+0

如果您说哪个版本的Boost,并显示失败的代码,并显示xtime.hpp的第23行,并将您的代码减少到最小例。事实上,这个问题根本无法回答。 –

+0

我已经编辑了问题以包含Boost版本和xtime.hpp。失败的代码只是一个导入语句。 – user650261

+0

您不必复制和粘贴Boost代码。显示*你的代码,你试图编译。 –

回答

1

的进口既然你不显示验证码,我们只能猜测。我的猜测是,你在你的代码中的某个地方定义了TIME_UTC宏。这个宏搞砸了xtime.hpp头。

+2

我没有在我的代码中的任何地方定义TIME_UTC。 – user650261

+0

@ user650261预处理整个翻译单元并在预处理的代码中找到此行。 –

+0

明白了,谢谢! – user650261

4

如果您在使用Boost时遇到语法错误,则可能需要使用-std=c++11编译您的代码。

您可能已经阅读的TIME_UTC问题是使用C++ 11的副作用。 TIME_UTC现在定义为C++ 11中的宏,因此您需要将TIME_UTC的所有实例替换为TIME_UTC_,或者仅使用更新(1.50.0+)版本的Boost,并且已经修复。

请参见:https://svn.boost.org/trac/boost/ticket/6940

+0

小记:它是C11(由C的time.h完成),而不是C++ 11(它不限于C++) – DrYak

10

对于运行到同样的问题,努力在这里找到解决方案。 从noodlebox派生”链接(https://svn.boost.org/trac/boost/ticket/6940):

您可以编辑/usr/include/boost/thread/xtime.hpp(或徘徊无论你xtime.hpp谎言) 和改变TIME_UTC所有出现TIME_UTC_ - 可能在第23行和第71行左右。

+5

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

+0

有这个错误编译PCL 1.7.1库提高1.49.0。这解决了这个问题(但驱使我到其他错误 - 哦,我的!)。 – Bull