2013-07-11 47 views
6

私はBoostを使ってC++プロジェクトに取り組んでいましたが、コンパイルの間に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_に変更しようとしましたが、これは別のサイトで私に推奨されていましたが、それは役に立たなかったようです。

EDIT: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 

EDIT:それを明確にするために、コードはあなたのコードが表示されませんので、我々は唯一の推測することができ、ブースト/ thread.hpp

+0

Boostのバージョンを教えて、失敗したコードを示し、xtime.hppの23行目のコードを示し、コードを最小限に抑えたら例。実際、この質問は、それが立て続けに答えることは不可能です。 –

+0

私はBoostのバージョンとxtime.hppのバージョンを含めるように質問を編集しました。失敗したコードは単なるimportステートメントです。 – user650261

+0

ブーストコードをコピー&ペーストする必要はありません。コンパイルしようとしている*コードを表示してください。 –

答えて

1

のインポートに失敗しているが。私の推測では、あなたのコードのどこかにTIME_UTCマクロを定義するということです。このマクロは、xtime.hppヘッダーをめちゃくちゃにします。

+2

私はどこにでもTIME_UTCを定義しません。 – user650261

+0

@ user650261翻訳単位全体を前処理し、前処理されたコードでこの行を探します。 –

+0

それは働いて、ありがとう! – user650261

4

ブーストを使用するときに構文エラーが発生する場合は、コードを-std=c++11でコンパイルする必要があります。

あなたが読んでいるかもしれないTIME_UTCの問題は、C++ 11の副作用です。 TIME_UTCはC++ 11のマクロとして定義されているので、のすべてのインスタンスをTIME_UTC_に置き換えるか、またはこれが既に修正されているBoostの新しいバージョン(1.50.0+)を使用する必要があります。

参照:https://svn.boost.org/trac/boost/ticket/6940同じ問題に実行している人のために

+0

小文字:C++ 11ではなく、C11(C++に限定されていません) – DrYak

10

、ここで解決策を見つけるのに苦労します。 noodlebox」リンク(https://svn.boost.org/trac/boost/ticket/6940)由来 :

あなたは/usr/include/boost/thread/xtime.hpp(またはwhereeverあなたxtime.hppがある) を編集し、TIME_UTCにTIME_UTC_のすべての出現を変更することができます - おそらく23行目から71行目までです。

+5

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

+0

ブースト1.49.0のPCL 1.7.1ライブラリをコンパイルするこのエラーはありませんでした。これはこの問題を解決しました(しかし、私を他のエラーに導きました - ああ私!)。 – Bull

関連する問題