c++eclipseboostproject

Error in C++ eclipse project using Boost libraries


I'm having some issues while compiling a C++ project in Eclipse. It works well, but when I include a boost header file (algorithm/string.hpp) it shows me theese errors:

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)

And when I use another library (iostream, vector, string, fstream...) it says that Eclipse couldn't found that library, but if I compile it without boost header it works. This is my code:

//============================================================================
// 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();
}

Solution

  • The third param to boost::split() needs to be a function (or 'callable'), not a string. Try

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

    is_any_of() is actually a constructor, but it constructs an object that can be called like a function.

    There is probably something better than is_any_of (ie something like is_equal) but I pulled it straight from the docs: http://www.boost.org/doc/libs/1_56_0/doc/html/string_algo/usage.html#idp432343152