2013-07-11 9 views
6

Ho lavorato su un progetto C++ usando Boost, e tra compilazioni, devo aver aggiornato qualcosa in boost senza significato o qualcosa, perché ora le dipendenze di Boost non verranno compilate:Errore di boost, problemi di compilazione 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 

Qualche idea? Ho provato a cambiare da TIME_UTC a TIME_UTC_ come mi è stato consigliato su un altro sito, ma ciò non mi è sembrato di aiuto.

MODIFICA: La versione Boost è la versione: 1.48.0.2. xtime Ho allegato qui di seguito:

// 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: Per chiarire, il codice sta fallendo su un import di boost/thread.hpp

+0

Sarebbe utile se tu dicessi quale versione di Boost, e mostri il codice che sta fallendo, e mostri cosa c'è sulla linea 23 di xtime.hpp, e riduci il tuo codice ad un minimo esempio. In realtà a questa domanda è impossibile rispondere così com'è. –

+0

Ho modificato la domanda per includere la versione di Boost e xtime.hpp. Il codice che sta fallendo è solo una dichiarazione di importazione. – user650261

+0

Non è necessario copiare e incollare codice Boost. Mostra * il tuo * codice che tenti di compilare. –

risposta

1

Dal momento che non si mostra il tuo codice, possiamo solo immaginare . La mia ipotesi è che tu definisca la macro TIME_UTC da qualche parte nel tuo codice. Questa macro scombina l'intestazione xtime.hpp.

+2

Non definisco TIME_UTC in nessun punto del mio codice. – user650261

+0

@ user650261 Pre-elaborare l'intera unità di traduzione e trovare questa riga nel codice preelaborato. –

+0

Funziona, grazie! – user650261

4

Se si verificano errori di sintassi durante l'utilizzo di Boost, potrebbe essere necessario compilare il codice con -std=c++11.

Il problema TIME_UTC di cui potresti aver letto è un effetto collaterale dell'uso di C++ 11. TIME_UTC è ora definito come una macro in C++ 11, quindi sarà necessario sostituire tutte le istanze di TIME_UTC con TIME_UTC_, o semplicemente utilizzare una versione più recente (1.50.0+) di Boost dove è già stato risolto.

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

+0

Piccola nota: è C11 (fatto da lib C's time.h), non C++ 11 (non è limitato a C++) – DrYak

10

Per quelli in esecuzione lo stesso problema e che lottano per trovare la soluzione qui. Derivato dal Noodlebox link'(https://svn.boost.org/trac/boost/ticket/6940):

È possibile modificare /usr/include/boost/thread/xtime.hpp (o dovunque il tuo xtime.hpp giace) e cambiare tutte le occorrenze di TIME_UTC a TIME_UTC_ - Probabilmente attorno alle linee 23 e 71.

+5

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

+0

Si è verificato questo errore durante la compilazione di librerie PCL 1.7.1 con boost 1.49.0. Questo ha risolto questo problema (ma mi ha portato ad un altro errore - oh mio!). – Bull