使用 Boost 库的 C++ eclipse 项目出错

问题描述 投票:0回答:1

我在 Eclipse 中编译 C++ 项目时遇到一些问题。 它工作得很好,但是当我包含 boost 头文件(algorithm/string.hpp)时,它会显示这些错误:

16:25:53 **** Incremental Build of configuration Debug for project Emulator ****
make all 
Building file: ../src/Emulator.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/lib/qt/include -I/root/boost/boost/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Emulator.d" -MT"src/Emulator.d" -o "src/Emulator.o" "../src/Emulator.cpp"
In file included from /usr/include/boost/algorithm/string/finder.hpp:23:0,
                 from /usr/include/boost/algorithm/string/find.hpp:22,
                 from /usr/include/boost/algorithm/string/predicate.hpp:23,
                 from /root/boost/boost/algorithm/string.hpp:21,
                 from ../src/Emulator.cpp:12:
/usr/include/boost/algorithm/string/detail/finder.hpp: En la instanciación de ‘boost::iterator_range<Iterator> boost::algorithm::detail::token_finderF<PredicateT>::operator()(ForwardIteratorT, ForwardIteratorT) const [with ForwardIteratorT = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; PredicateT = const char*]’:
/usr/include/boost/algorithm/string/concept.hpp:43:28:   se requiere desde ‘void boost::algorithm::FinderConcept<FinderT, IteratorT>::constraints() [with FinderT = boost::algorithm::detail::token_finderF<const char*>; IteratorT = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]’
/usr/include/boost/concept/detail/has_constraints.hpp:32:62:   se requiere para la sustitución de ‘template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model:: constraints)>*) [with Model = boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >]’
/usr/include/boost/concept/detail/has_constraints.hpp:42:5:   se requiere desde ‘const bool boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >::value’
/usr/include/boost/concept/detail/has_constraints.hpp:45:31:   se requiere desde ‘struct boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >’
/usr/include/boost/mpl/if.hpp:67:11:   se requiere desde ‘struct boost::mpl::if_<boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >, boost::concepts::constraint<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >, boost::concepts::requirement<boost::concepts::failed************ boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >::************> >’
/usr/include/boost/concept/detail/general.hpp:50:8:   se requiere desde ‘struct boost::concepts::requirement_<void (*)(boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >)>’
/usr/include/boost/algorithm/string/iter_find.hpp:77:13:   se requiere desde ‘SequenceSequenceT& boost::algorithm::iter_split(SequenceSequenceT&, RangeT&, FinderT) [with SequenceSequenceT = std::vector<std::basic_string<char> >; RangeT = std::basic_string<char>; FinderT = boost::algorithm::detail::token_finderF<const char*>]’
/usr/include/boost/algorithm/string/split.hpp:149:69:   se requiere desde ‘SequenceSequenceT& boost::algorithm::split(SequenceSequenceT&, RangeT&, PredicateT, boost::algorithm::token_compress_mode_type) [with SequenceSequenceT = std::vector<std::basic_string<char> >; RangeT = std::basic_string<char>; PredicateT = const char*]’
../src/Emulator.cpp:23:27:   se requiere desde aquí
/usr/include/boost/algorithm/string/detail/finder.hpp:583:45: error: expression cannot be used as a function
                             while( It2!=End && m_Pred(*It2) ) ++It2;
                                             ^
In file included from /usr/include/c++/4.8.3/algorithm:62:0,
                 from /usr/include/c++/4.8.3/ext/slist:47,
                 from /usr/include/boost/algorithm/string/std/slist_traits.hpp:16,
                 from /usr/include/boost/algorithm/string/std_containers_traits.hpp:23,
                 from /root/boost/boost/algorithm/string.hpp:18,
                 from ../src/Emulator.cpp:12:
/usr/include/c++/4.8.3/bits/stl_algo.h: En la instanciación de ‘_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _Predicate = const char*]’:
/usr/include/c++/4.8.3/bits/stl_algo.h:4465:41:   se requiere desde ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _Predicate = const char*]’
/usr/include/boost/algorithm/string/detail/finder.hpp:570:74:   se requiere desde ‘boost::iterator_range<Iterator> boost::algorithm::detail::token_finderF<PredicateT>::operator()(ForwardIteratorT, ForwardIteratorT) const [with ForwardIteratorT = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; PredicateT = const char*]’
/usr/include/boost/algorithm/string/concept.hpp:43:28:   se requiere desde ‘void boost::algorithm::FinderConcept<FinderT, IteratorT>::constraints() [with FinderT = boost::algorithm::detail::token_finderF<const char*>; IteratorT = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]’
/usr/include/boost/concept/detail/has_constraints.hpp:32:62:   se requiere para la sustitución de ‘template<class Model> boost::concepts::detail::yes boost::concepts::detail::has_constraints_(Model*, boost::concepts::detail::wrap_constraints<Model, (& Model:: constraints)>*) [with Model = boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >]’
/usr/include/boost/concept/detail/has_constraints.hpp:42:5:   se requiere desde ‘const bool boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >::value’
/usr/include/boost/concept/detail/has_constraints.hpp:45:31:   se requiere desde ‘struct boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >’
/usr/include/boost/mpl/if.hpp:67:11:   se requiere desde ‘struct boost::mpl::if_<boost::concepts::not_satisfied<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >, boost::concepts::constraint<boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > > >, boost::concepts::requirement<boost::concepts::failed************ boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >::************> >’
/usr/include/boost/concept/detail/general.hpp:50:8:   se requiere desde ‘struct boost::concepts::requirement_<void (*)(boost::algorithm::FinderConcept<boost::algorithm::detail::token_finderF<const char*>, __gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >)>’
/usr/include/boost/algorithm/string/iter_find.hpp:77:13:   se requiere desde ‘SequenceSequenceT& boost::algorithm::iter_split(SequenceSequenceT&, RangeT&, FinderT) [with SequenceSequenceT = std::vector<std::basic_string<char> >; RangeT = std::basic_string<char>; FinderT = boost::algorithm::detail::token_finderF<const char*>]’
/usr/include/boost/algorithm/string/split.hpp:149:69:   se requiere desde ‘SequenceSequenceT& boost::algorithm::split(SequenceSequenceT&, RangeT&, PredicateT, boost::algorithm::token_compress_mode_type) [with SequenceSequenceT = std::vector<std::basic_string<char> >; RangeT = std::basic_string<char>; PredicateT = const char*]’
../src/Emulator.cpp:23:27:   se requiere desde aquí
/usr/include/c++/4.8.3/bits/stl_algo.h:214:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:218:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:222:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:226:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:234:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:238:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
/usr/include/c++/4.8.3/bits/stl_algo.h:242:23: error: ‘__pred’ cannot be used as a function
    if (__pred(*__first))
                       ^
make: *** [src/Emulator.o] Error 1

16:26:04 Build Finished (took 11s.425ms)

当我使用另一个库(iostream、vector、string、fstream...)时,它说 Eclipse 无法找到该库,但如果我在没有 boost 标头的情况下编译它,它就可以工作。 这是我的代码:

//============================================================================
// Name        : Emulator.cpp
// Version     : 1.0
// Description : emulator main file
//============================================================================

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "/root/boost/boost/algorithm/string.hpp"

using namespace std;

void loadConfig()
{
    ifstream file("settings");
    string s;

    while(getline(file, s)) {
        vector<string> line;
        boost::split(line, s,"=");

        //Test
        cout << line[0] << " = " << line[1] << endl;
    }
}

void connect()
{

}

int main() {
    cout << "C++ emulator 1.0" << endl;
    cout << endl;

    cout << "Reading settings file..." << endl;
    loadConfig();

    cout << "Establishing connection to MySQL..." << endl;
    connect();
}
c++ eclipse boost project
1个回答
0
投票

boost::split()
的第三个参数必须是函数(或“可调用”),而不是字符串。 尝试一下

boost::split(line, s, boost::is_any_of("="));

is_any_of()
实际上是一个构造函数,但是它构造了一个可以像函数一样调用的对象。

可能有比

is_any_of
更好的东西(即类似
is_equal
的东西),但我直接从文档中提取它:http://www.boost.org/doc/libs/1_56_0/doc/html/string_algo/用法.html#idp432343152

© www.soinside.com 2019 - 2024. All rights reserved.