I'm very new with boost spirit (and with boost). Its very interesting library.
I use qtcreator + MinGW 5.3.
I simply add every source file from git_hub_calc8 into new project and add some boost library, but i got the following error trying to build (All other examples work fine)
C:\Program Files\boost\boost\boost\spirit\home\x3\nonterminal\rule.hpp:113: ошибка: undefined reference to `bool client::parser::parse_rule<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::spirit::x3::context<boost::spirit::x3::error_handler_tag, std::reference_wrapper<boost::spirit::x3::error_handler<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::x3::context<boost::spirit::x3::skipper_tag, boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const, boost::spirit::x3::unused_type> >, std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> > >(boost::spirit::x3::rule<client::parser::statement_class, std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> >, false>, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&, boost::spirit::x3::context<boost::spirit::x3::error_handler_tag, std::reference_wrapper<boost::spirit::x3::error_handler<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::spirit::x3::context<boost::spirit::x3::skipper_tag, boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const, boost::spirit::x3::unused_type> > const&, std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> >&)'
What did i wrong? How should i create project with this example?
Seems like a problem with BOOST_SPIRIT_DECLARE beacause a place pointed out by error is call for a template function connected with this define
(template <typename Iterator, typename Context, typename Attribute_>
bool parse(Iterator& first, Iterator const& last
, Context const& context, unused_type, Attribute_& attr) const
{
return parse_rule(*this, first, last, context, attr);
}
The BOOST_SPIRIT_INSTANTIATE marco is equivalent to doing
namespace client { namespace parser
{
template bool parse_rule<iterator_type, context_type, statement_type::attribute_type>(
statement_type rule_, iterator_type &first, iterator_type const &last,
context_type const &context,
statement_type ::attribute_type &attr);
;
}}
So the crucial bit is that iterator_type and context_type match exactly the ones required at the call site. Now, the unresolved symbol is (demangled):
bool client::parser::parse_rule<
__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
boost::spirit::x3::context<
boost::spirit::x3::error_handler_tag,
std::reference_wrapper<boost::spirit::x3::error_handler<__gnu_cxx::__normal_iterator<
char const *, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >,
boost::spirit::x3::context<
boost::spirit::x3::skipper_tag,
boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const,
boost::spirit::x3::unused_type> >,
std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> >
>
(boost::spirit::x3::rule<client::parser::statement_class, std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> >, false>,
__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&,
__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&,
boost::spirit::x3::context<
boost::spirit::x3::error_handler_tag,
std::reference_wrapper<boost::spirit::x3::error_handler<__gnu_cxx::__normal_iterator<
char const *, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >,
boost::spirit::x3::context<
boost::spirit::x3::skipper_tag,
boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const,
boost::spirit::x3::unused_type> > const &,
std::__cxx11::list<client::ast::statement, std::allocator<client::ast::statement> >&)
This implies the iterator_type should be:
__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
Which is indeed what std::string::const_iterator expands to on my system. So, the mismatch is likely in the context type. By adding a forced type error above the BOOST_SPIRIT_INSTANTIATE invocation like so:
struct {} _ = *static_cast<client::parser::context_type*>(nullptr);
I was able to force the compiler to output the expanded type of context_type at the point of instantiation:
statement.cpp:12 error: conversion from ‘client::parser::context_type {aka boost::spirit::x3::context<boost::spirit::x3::error_handler_tag, const std::reference_wrapper<boost::spirit::x3::error_handler<__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> > > >, boost::spirit::x3::context<boost::spirit::x3::skipper_tag, const boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag>, boost::spirit::x3::unused_type> >}’ to non-scalar type ‘client::parser::<anonymous struct>’ requested
Which tells us the context type is (formatted for legibility):
boost::spirit::x3::context<
boost::spirit::x3::error_handler_tag,
const std::reference_wrapper<boost::spirit::x3::error_handler<
__gnu_cxx::__normal_iterator<const char *, std::__cxx11::basic_string<char> > > >,
boost::spirit::x3::context<
boost::spirit::x3::skipper_tag,
boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const,
boost::spirit::x3::unused_type> >,
BUT: the linker has it as
boost::spirit::x3::context<
boost::spirit::x3::error_handler_tag,
std::reference_wrapper<boost::spirit::x3::error_handler<
__gnu_cxx::__normal_iterator<const char *, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >,
boost::spirit::x3::context<
boost::spirit::x3::skipper_tag,
boost::spirit::x3::char_class<boost::spirit::char_encoding::ascii, boost::spirit::x3::space_tag> const,
boost::spirit::x3::unused_type> >
The most conspicuous difference is in the spelling of the defaulted template arguments on std::basic_string (char_traits and the allocator), but that's not actually a difference. The difference that DOES matter, though, is the absense of const with the reference_wrapper<> type.
Fixing It
I suppose this might have been a change once upon a time in the history of X3. The easiest fix in this case is to drop the const in config.hpp:
typedef x3::context<
error_handler_tag
, std::reference_wrapper<error_handler_type>
, phrase_context_type>
context_type;
And indeed, it now compiles
Related
ThreadSanitizer gives me an alleged race condition in boost::regex_match. Is this a false positive? I cannot find synchronization primitives that depend on BOOST_HAS_THREADS in the callstacks. All input parameters are on the stack of the respective thread and not shared.
==================
WARNING: ThreadSanitizer: data race (pid=1893)
Write of size 4 at 0x007e19fa8ff0 by thread T36:
#0 boost::re_detail_106700::saved_state::saved_state(unsigned int) include/boost/regex/v4/perl_matcher_non_recursive.hpp:59
#1 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::push_recursion_stopper() include/boost/regex/v4/perl_matcher_non_recursive.hpp:288
#2 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_all_states() include/boost/regex/v4/perl_matcher_non_recursive.hpp:202
#3 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_prefix() include/boost/regex/v4/perl_matcher_common.hpp:336
#4 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp() include/boost/regex/v4/perl_matcher_common.hpp:220
#5 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match() include/boost/regex/v4/perl_matcher_common.hpp:193
#6 bool boost::regex_match<char const*, std::allocator<boost::sub_match<char const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) include/boost/regex/v4/regex_match.hpp:50
#7 bool boost::regex_match<char, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) /var/lib/jenkins/workspace/nightly-jnd-navigation__tsd-nav-rsi-viwi-dev/system/ext-boost-dev/dist/17-89ad-bc06/usr/include/boost/regex/v4/regex_match.hpp:73 (tsd.nav.mainapp.mib3+0x3dd0610)
<...>
Previous write of size 4 at 0x007e19fa8ff0 by thread T105:
[failed to restore the stack]
Location is heap block of size 4096 at 0x007e19fa8000 allocated by thread T105:
#0 operator new(unsigned long) <null> (libtsan.so.0+0x79f54)
#1 boost::re_detail_106700::save_state_init::save_state_init(boost::re_detail_106700::saved_state**, boost::re_detail_106700::saved_state**) include/boost/regex/v4/perl_matcher_non_recursive.hpp:107
#2 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp() include/boost/regex/v4/perl_matcher_common.hpp:202
#3 boost::re_detail_106700::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match() include/boost/regex/v4/perl_matcher_common.hpp:193
#4 bool boost::regex_match<char const*, std::allocator<boost::sub_match<char const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) include/boost/regex/v4/regex_match.hpp:50
#5 bool boost::regex_match<char, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) include/boost/regex/v4/regex_match.hpp:73
<...>
Regards
I think the documentation is pretty definitive:
Thread Safety
The Boost.Regex library is thread safe when Boost is: you can verify
that Boost is in thread safe mode by checking to see if
BOOST_HAS_THREADS is defined: this macro is set automatically by the
config system when threading support is turned on in your compiler.
Class basic_regex and its typedefs regex and wregex are thread safe,
in that compiled regular expressions can safely be shared between
threads. The matching algorithms regex_match, regex_search, and
regex_replace are all re-entrant and thread safe. Class match_results
is now thread safe, in that the results of a match can be safely
copied from one thread to another (for example one thread may find
matches and push match_results instances onto a queue, while another
thread pops them off the other end), otherwise use a separate instance
of match_results per thread.
The POSIX API functions are all re-entrant and thread safe, regular
expressions compiled with regcomp can also be shared between threads.
The class RegEx is only thread safe if each thread gets its own RegEx
instance (apartment threading) - this is a consequence of RegEx
handling both compiling and matching regular expressions.
Finally note that changing the global locale invalidates all compiled
regular expressions, therefore calling set_locale from one thread
while another uses regular expressions will produce unpredictable
results.
There is also a requirement that there is only one thread executing
prior to the start of main().
So, you need to make sure:
you are not sharing the match_results object (your description doesn't say, because that's not an input argument depending on your definition)
the regex is pre-compiled:
[are] thread safe,
in that compiled regular expressions can safely be shared between
threads
I am trying to compile Boost 1.79.0 in a cluster using the GCC compiler version 12.1.0 that I have compiled manually since the GCC version of the cluster is very old.
After compiling GCC, I have exported the following paths in a shell script that I source every time in the terminal before installing or running a program. I have manually installed CMake and several programs.
However, I am still struggling with compiling Boost. It is complaining about undefined references in C++11 so I guess there is something that is linked wrongly.
Could anyone provide any suggestions to overcome this issue?
Here is my exports in the shell script:
export PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin:$PATH
export CFLAGS="-I /lustre/home/ucemkmo/Softwares/gcc-12.1.0/include";
export LDFLAGS="-L /lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64";
export CPPFLAGS="-I /lustre/home/ucemkmo/Softwares/gcc-12.1.0/include";
export CXXFLAGS="-L /lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64";
export LD_LIBRARY_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64:$LD_LIBRARY_PATH
export LD_RUN_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64
export LD="/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++"
export MANPATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/man:$MANPATH
export INFOPATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/info:$INFOPATH
export INFO_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/info:$INFO_PATH
export AR=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gcc-ar
export CC=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gcc
export CXX=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++
export LD=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++
export CXXCPP="/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++ -E"
export FC=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export F77=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export F90=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export COLLECT_GCC=gcc
export COLLECT_LTO_WRAPPER=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/12.1.0/lto-wrapper
export PATH=/lustre/home/ucemkmo/Softwares/cmake-3.24.0/bin:$PATH
export PATH=/lustre/home/ucemkmo/Softwares/python-3.10.5/3.10.5/bin:$PATH
export PETSC_DIR=/lustre/home/ucemkmo/Softwares/petsc
export PETSC_ARCH=arch-linux-c-opt
Here are the error messages I am receiving during the compilation of Boost v1.79.0:
Building B2 engine..
###
###
### Using 'gcc' toolset.
###
###
g++ (GCC) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
###
###
> g++ -x c++ -std=c++11 -O2 -s -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp execunix.cpp filesys.cpp filent.cpp fileunix.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam_strings.cpp jam.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp pathunix.cpp regexp.cpp rules.cpp scan.cpp search.cpp startup.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp -o b2
/tmp/cc1S1rUW.o: In function `builtin_normalize_path(frame*, int)':
builtins.cpp:(.text+0x14ea): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
builtins.cpp:(.text+0x1510): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cc8w84jf.o: In function `debug_print_frame_info(_frame_info&)':
debugger.cpp:(.text+0x3d7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
/tmp/cc8w84jf.o: In function `debug_frame_read(_IO_FILE*, _frame_info*)':
debugger.cpp:(.text+0x1707): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
/tmp/cceSnutQ.o: In function `var_parse_to_string(VAR_PARSE_GROUP*, bool)':
function.cpp:(.text+0x1683): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x16b5): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x171c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1770): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x17b3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cceSnutQ.o:function.cpp:(.text+0x17d3): more undefined references to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)' follow
/tmp/cceSnutQ.o: In function `var_parse_to_string(VAR_PARSE_VAR const*, bool)':
function.cpp:(.text+0x193f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
function.cpp:(.text+0x19b0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1a2e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1ae2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1b40): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
function.cpp:(.text+0x1bf3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1c3e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccwxFfFi.o: In function `errno_printf(char const*, ...)':
output.cpp:(.text+0x69d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
output.cpp:(.text+0x732): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
output.cpp:(.text+0x7a2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x8bb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x8f0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x92a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x953): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x9bd): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
output.cpp:(.text+0xa81): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
/tmp/cc7flVRU.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) [clone .isra.0]':
pathsys.cpp:(.text+0x68): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/cc7flVRU.o: In function `b2::paths::normalize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
pathsys.cpp:(.text+0x51d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
pathsys.cpp:(.text+0x59d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const'
pathsys.cpp:(.text+0x5ee): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x62d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
pathsys.cpp:(.text+0x6e7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x711): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x761): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
/tmp/ccR9xr0R.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .isra.0]':
startup.cpp:(.text+0x68): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccR9xr0R.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) [clone .isra.0]':
startup.cpp:(.text+0x108): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccR9xr0R.o: In function `b2::startup::builtin_boost_build(frame*, int)':
startup.cpp:(.text+0x3d2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x459): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x70a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x86f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x8d2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x986): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccR9xr0R.o: In function `b2::startup::bootstrap(frame*)':
startup.cpp:(.text+0x1045): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x114d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const'
startup.cpp:(.text+0x14e5): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1517): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1658): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x168a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1852): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/ccR9xr0R.o:startup.cpp:(.text+0x1884): more undefined references to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)' follow
/tmp/ccR9xr0R.o: In function `b2::startup::bootstrap(frame*)':
startup.cpp:(.text+0x1a46): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1ba6): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x1c6e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x1c93): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1ceb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1d3e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccR9xr0R.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
startup.cpp:(.text._ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_SA_[_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_SA_]+0x42): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cceOb6PB.o: In function `cwd_init()':
cwd.cpp:(.text+0x87): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
/tmp/cceOb6PB.o: In function `_GLOBAL__sub_I__Z8cwd_initv':
cwd.cpp:(.text.startup+0xb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
collect2: error: ld returned 1 exit status
> cp b2 bjam
cp: cannot stat ‘b2’: No such file or directory
Failed to build B2 build engine
It seems that you are facing a problem regarding Dual ABIs:
If you get linker errors about undefined references to symbols that
involve types in the std::__cxx11 namespace or the tag [abi:cxx11]
then it probably indicates that you are trying to link together object
files that were compiled with different values for the
_GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If
the third-party library cannot be rebuilt with the new ABI then you
will need to recompile your code with the old ABI.
In other words, some of the boost dependencies has been compiled using your old gcc. See the full page in gcc documentation, here.
I have a cephfs and i'm writing a client code in c language using libcephfs.h library for it.
Note: installed libcephfs-dev and libcephfs2, but did not work on any version(12.2.12 or 12.2.4) I am using ubuntu 18.04.3.
#include "/usr/include/cephfs/libcephfs.h"
#include <stdlib.h>
#include <stdio.h>
int main (int argc, const char* argv[]){
struct ceph_mount_info *cmount;
const char id[] = "client.admin";
int err = ceph_create(&cmount, id);
printf("%d", err);
return 0;
}
$ g++ -o example example.c -lcephfs
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::unregister_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph_clock_now()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::register_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, AdminSocketHook*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCountersBuilder::add_u64_counter(int, char const*, char const*, char const*, int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::set_val(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, bool, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `CrushWrapper::get_full_location_ordered(int, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, utime_t, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_env()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_argv(std::vector<char const*, std::allocator<char const*> >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph::Formatter::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, std::chrono::duration<unsigned long, std::ratio<1l, 1000000000l> >, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `FSMap::parse_role(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mds_role_t*, std::ostream&) const'
collect2: error: ld returned 1 exit status
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <cephfs/libcephfs.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, const char* argv[]){
struct ceph_mount_info *cmount;
const char id[] = "client.admin";
int err = ceph_create(&cmount, id);
printf("%d", err);
return 0;
}
This code compiles for me on Ubuntu 18.04 with the GCC 7 compiler.
The command I used to compile is :
g++ -o example example.c -lcephfs
In fact, even your source compiles on my system with the added #defines that I have used.
It worked ! Before upgrading my ubuntu version(from 16.04 to 18.04), i have installed librados. Now, i reinstall librados and libcephfs. It worked successfully.
I am trying to build DeepLabv2's version of caffe.
I am using anaconda2 for package management.
I get the following errors:
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
/usr/bin/ld: warning: libhdf5.so.10, needed by /home/asim/anaconda2/lib/libmatio.so, not found (try using -rpath or -rpath-link)
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::DebugString[abi:cxx11]() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::ParseFromString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::NameOfEnum[abi:cxx11](google::protobuf::EnumDescriptor const*, int)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::AssignDescriptors(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::internal::MigrationSchema const*, google::protobuf::Message const* const*, unsigned int const*, google::protobuf::MessageFactory*, google::protobuf::Metadata*, google::protobuf::EnumDescriptor const**, google::protobuf::ServiceDescriptor const**)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
/home/asim/anaconda2/lib/libmatio.so: undefined reference to `H5Rdereference'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::MessageLite::SerializeToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::ArenaStringPtr::AssignWithDefault(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, google::protobuf::internal::ArenaStringPtr)'
collect2: error: ld returned 1 exit status
Makefile:621: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
I tried to add Library Directories to the Makefile.
Specifically
LIBRARY_DIRS += /home/asim/anaconda2/lib /lib/x86_64-linux-gnu/
But it is not working.
Trying to compile this cfgparser example.
$ g++ example.cc -lcfgparser
: In function `main':
example.cc:(.text+0x6b): undefined reference to `ConfigParser_t::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
example.cc:(.text+0x160): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0x2d9): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int*) const'
example.cc:(.text+0x43c): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double*) const'
example.cc:(.text+0x5b1): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool*) const'
example.cc:(.text+0x78c): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) const'
example.cc:(.text+0xa15): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xba2): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xd15): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xe7f): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
collect2: error: ld returned 1 exit statu
But clearly those symbols are there:
$ nm -gC /usr/lib/libcfgparser.so
000000000003710 T ConfigParser_t::readFile(std::string const&)
0000000000004880 T ConfigParser_t::ConfigParser_t(std::string const&)
00000000000024c0 T ConfigParser_t::ConfigParser_t()
0000000000004ad0 T ConfigParser_t::ConfigParser_t(std::string const&)
00000000000024a0 T ConfigParser_t::ConfigParser_t()
0000000000004d20 T ConfigParser_t::getOptions(std::string const&) const
00000000000028d0 T ConfigParser_t::getSections() const
0000000000002ff0 T ConfigParser_t::getValue(std::string, std::string, bool*) const
0000000000002de0 T ConfigParser_t::getValue(std::string, std::string, double*) const
0000000000002bd0 T ConfigParser_t::getValue(std::string, std::string, int*) const
00000000000027d0 T ConfigParser_t::getValue(std::string, std::string, std::string*) const
0000000000003500 T ConfigParser_t::getValue(std::string, std::string, std::vector<std::string, std::allocator<std::string> >*) const
Unlike other similar problems on SO, this is NOT about linking order, as there is only one object file being linked. Anything I'm missing??
But clearly those symbols are there:
Clearly, they're not. Take a closer look and you will see that
there are no matches between the signatures reported by your
linker as undefined and those reported from the library by
nm.
The Standard header <string> defines std::string as typedef for:
std::basic_string<char, std::char_traits<char>, std::allocator<char>>
The GCC implementation of <string>, as of the cxx11 ABI (GCC 4.7.0)
defines std::string as a typedef for:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>
The std::__cxx11 name space encloses types whose binary implementations are
compliant with the cxx11 ABI.
That type definition means that C++ translation unit that includes the Standard header <string> won't
compile, with GCC >= 4.7, into object code containing a symbol that demangles as std::string.
If a binary - like your libcfgparser.so - contains a symbol that demangles as std::string, then
whatever that symbol might have referred to in the sources from which it was built, it does not refer to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>,
and cannot be linked with other binaries that were compiled with that definition of std::string.
Your libcfgparser.so is the one installed by libcfgparser0_1.1.2_amd64.deb from the
cfgparser Sourceforce project
(which was last updated three years ago). I guess this from that the fact that I
get your linkage error with same example.cc program linked against the library that is installed by that package.
The explanation for the error is revealed by:
/usr/lib$ strings -a libcfgparser.so | grep "GCC: ("
GCC: (Debian 4.3.2-1.1) 4.3.2
...
which tells us that this library was built with GCC 4.3.2 - pre the cxx11 ABI.
The std::string that appears in your nm output is a pre-cxx11 demangling abbreviation
of std::basic_string<char, std::char_traits<char>, std::allocator<char>>.
This libcfgparser.so is ABI-incompatible with your current GCC, so you
can't link it with programs that you build with that compiler. What you can do is
build libcfgparser from the source package, libcfgparser-1.1.2.tar.bz2,
with your current compiler and then link your programs with the library you have
built yourself.
That works, but not effortlessly. First you'll need to fix the broken
and antiquated autotooling of the source package to create a working ./configure
script.
Which doesn't give a reassuring impression of the proficiency of the package maintainer.
Plus the source code of the package, copyright 2008, is of amateur quality. If
what you are after is a C++ parser for INI-style files, then boost::property_tree::ini_parser would be the
goto solution. See this answer