2013-07-11 37 views
6

Tôi đã làm việc trên một dự án C++ bằng cách sử dụng Boost, và giữa các biên dịch, tôi phải nâng cấp thứ gì đó mà không có ý nghĩa gì đó, bởi vì bây giờ Tăng phụ thuộc sẽ không biên dịch:Lỗi tăng, rắc rối biên dịch 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 

Bất kỳ ý tưởng nào? Tôi đã thử thay đổi TIME_UTC thành TIME_UTC_ vì điều này đã được đề xuất cho tôi trên một trang web khác, nhưng điều đó dường như không giúp ích gì.

EDIT: Phiên bản tăng cường là Phiên bản: 1.48.0.2. Tôi đã gắn xtime dưới đây:

// 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 

EDIT: Để làm cho nó rõ ràng, các mã được thất bại trên một nhập khẩu tăng/thread.hpp

+0

Sẽ rất hữu ích nếu bạn nói phiên bản nào của Boost và hiển thị mã không thành công và hiển thị dòng 23 trên xtime.hpp và giảm mã của bạn xuống mức tối thiểu thí dụ. Trong thực tế, câu hỏi này là không thể trả lời khi nó đứng. –

+0

Tôi đã chỉnh sửa câu hỏi để bao gồm phiên bản Boost và xtime.hpp. Mã không thành công chỉ là một câu lệnh nhập khẩu. – user650261

+0

Bạn không phải sao chép và dán mã Boost. Hiển thị * mã * của bạn mà bạn cố gắng biên dịch. –

Trả lời

1

Vì bạn không hiển thị mã của bạn, chúng tôi chỉ có thể đoán . Đoán của tôi là bạn xác định TIME_UTC macro ở đâu đó trong mã của bạn. Macro này làm lộn xộn xtime.hpp tiêu đề.

+2

Tôi không xác định TIME_UTC ở bất kỳ đâu trong mã của mình. – user650261

+0

@ user650261 Preprocess toàn bộ đơn vị dịch và tìm dòng này trong mã được xử lý trước. –

+0

Đã làm việc, cảm ơn! – user650261

4

Nếu bạn gặp lỗi cú pháp khi sử dụng Boost, bạn có thể cần phải biên dịch mã của mình bằng -std=c++11.

Vấn đề TIME_UTC bạn có thể đã đọc là tác dụng phụ của việc sử dụng C++ 11. TIME_UTC hiện được định nghĩa là macro trong C++ 11, vì vậy, bạn sẽ cần phải thay thế tất cả các phiên bản TIME_UTC bằng TIME_UTC_ hoặc chỉ sử dụng phiên bản Boost (1.50.0+) mới hơn, nơi điều này đã được sửa.

Xem: https://svn.boost.org/trac/boost/ticket/6940

+0

Ghi chú nhỏ: đó là C11 (do lib C's time.h) thực hiện, không phải C++ 11 (không giới hạn ở C++) – DrYak

10

Đối với những người chạy vào cùng một vấn đề và phải vật lộn để tìm ra giải pháp ở đây. Xuất phát từ noodlebox liên kết'(https://svn.boost.org/trac/boost/ticket/6940):

Bạn có thể sửa /usr/include/boost/thread/xtime.hpp (hoặc bất cứ nơi nào xtime.hpp của bạn nằm) và thay đổi tất cả các lần xuất hiện của TIME_UTC để TIME_UTC_ - Có lẽ xung quanh các dòng 23 và 71.

+5

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

+0

Đã xảy ra lỗi khi biên dịch các thư viện PCL 1.7.1 với mức tăng 1.49.0. Điều này giải quyết vấn đề này (nhưng đã khiến tôi gặp lỗi khác - oh my!). – Bull