Clang boost oddities - macos

I am doing a pet project and am using clang++ (specifically MacPorts clang 3.1). So I decided to switch over to libc++ (to use std::array and such) but I was using boost (specifically asio and regex), so I had to recompile boost using libc++. I removed boost which was installed in macports and build boost from source and now is installed in /usr/local/include and /usr/local/lib. Ever since then, I cannot compile. Here are the oddities I am encountering:
When executing:
clang++ -g -std=c++11 -stdlib=libc++ -c main.cpp
I get a weird compile error having to do with the move constructor (there's more to this error, but as you can see it is coming from boost):
/usr/include/c++/v1/string:1952:10: error: overload resolution selected implicitly-deleted copy assignment operator
__r_ = _STD::move(__str.__r_);
^
/usr/include/c++/v1/string:1942:9: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
__move_assign(__str, true_type());
^
/usr/include/c++/v1/string:1961:5: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
__move_assign(__str, integral_constant<bool,
^
/usr/local/include/boost/regex/v4/perl_matcher.hpp:207:16: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=' requested here
s1 = traits_inst.transform(a, a + 1);
However, when I execute (please note the "-I", and it must be in that exact position):
clang++ -I -std=c++11 -stdlib=libc++ -g -c main.cpp
This compiles (but linking fails later on). Why is this? What does -I do without a path? Must -stdlib= be preceded with -I?
Now the fun part:
Even though, everything compiles now, it won't link. When executing:
clang++ main.o FTPClient.o FTPConnection.o -lboost_system -lboost_regex -std=c++11 -stdlib=libc++ -g -o cli
I get the message:
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname(char const*, char const*) const in libboost_regex.a(instances.o)
ld: symbol(s) not found for architecture x86_64
Now I am thinking maybe I a missing some -lboost flag but I am not sure what it is. What could be the reason for this?
Thanks very much!
EDIT: When looking through the logs of installing boost, I noticed this:
..failed clang-darwin.link.dll /usr/local/lib/libboost_filesystem.dylib...
clang-darwin.link.dll /usr/local/lib/libboost_regex.dylib
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::c_regex_traits<char>::transform(char const*, char const*) in c_regex_traits.o
boost::c_regex_traits<char>::lookup_classname(char const*, char const*) in c_regex_traits.o
boost::c_regex_traits<char>::lookup_collatename(char const*, char const*) in c_regex_traits.o
boost::re_detail::RegExData::update() in cregex.o
boost::RegEx::What(int) const in cregex.o
boost::re_detail::pred2::operator()(boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > const&) in cregex.o
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in instances.o
...
"__ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initIPKwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::c_regex_traits<wchar_t>::transform(wchar_t const*, wchar_t const*) in wc_regex_traits.o
boost::c_regex_traits<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) in wc_regex_traits.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_collatename(wchar_t const*, wchar_t const*) const in winstances.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname_imp(wchar_t const*, wchar_t const*) const in winstances.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) const in winstances.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does this mean boost regex maybe incompatible with -libc++?
EDIT 2: I tried using std::regex, but I get this:
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in main.o
unsigned int std::__1::regex_traits<char>::__lookup_classname<char const*>(char const*, char const*, bool, char) const in main.o
ld: symbol(s) not found for architecture x86_64

A helpful, but unsatisfactory answer: libc++ contains std::regex, which you can use instead of boost::regex.

Related

get link error when use protobuf 3 in xcode

first,I installed google protobuf-3.3 (protobuf-cpp-3.3.0.tar.gz), use xcode to create a crossplatform game project, the target is ios, add libprotobuf-lite.tbd and libprotobuf.tbd, then create a test.proto file like this:
syntax = "proto3";
message Person {
string name = 1;
}
use protoc to compile it to cpp file: test.pb.h,test.pb.cc
when run the project, I got 13 errors:
Undefined symbols for architecture arm64:
"google::protobuf::Message::SpaceUsedLong() const", referenced from:
vtable for Person in test.pb.o
"google::protobuf::internal::WireFormatLite::VerifyUtf8String(char const*, int, google::protobuf::internal::WireFormatLite::Operation, char const*)", referenced from:
Person::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) in test.pb.o
Person::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream*) const in test.pb.o
Person::InternalSerializeWithCachedSizesToArray(bool, unsigned char*) const in test.pb.o
"google::protobuf::UnknownFieldSet::default_instance()", referenced from:
google::protobuf::internal::InternalMetadataWithArena::default_instance() in test.pb.o
"google::protobuf::io::CodedInputStream::ReadTagFallback(unsigned int)", referenced from:
Person::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream*) in test.pb.o
"google::protobuf::internal::RegisterAllTypes(google::protobuf::Metadata const*, int)", referenced from:
protobuf_test_2eproto::(anonymous namespace)::protobuf_RegisterTypes(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in test.pb.o
...
...
...

scan business card address using dessert library but getting a linking error

I'm getting following linking error when compiled.
Undefined symbols for architecture x86_64:
"tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
-[Tesseract recognizedText] in Tesseract.o
"tesseract::TessBaseAPI::SetVariable(char const*, char const*)", referenced from:
-[Tesseract setVariableValue:forKey:] in Tesseract.o
-[Tesseract loadVariables] in Tesseract.o
"tesseract::TessBaseAPI::Init(char const*, char const*, tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*, GenericVector<STRING> const*, bool)", referenced from:
tesseract::TessBaseAPI::Init(char const*, char const*) in Tesseract.o
"tesseract::TessBaseAPI::Version()", referenced from:
+[Tesseract version] in Tesseract.o
"tesseract::TessBaseAPI::SetImage(unsigned char const*, int, int, int, int)", referenced from:
-[Tesseract setImage:] in Tesseract.o
"tesseract::TessBaseAPI::Recognize(ETEXT_DESC*)", referenced from:
-[Tesseract recognize] in Tesseract.o
"tesseract::TessBaseAPI::TessBaseAPI()", referenced from:
-[Tesseract initWithDataPath:language:] in Tesseract.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
/Users/admin/Desktop/Screen Shot 2015-02-04 at 3.38.46 pm.png
how to resolve it.. or any other library that supports in iOS8...?

compiling litecoin OSX 10.9.1

I'm trying to compile the Litecoin source (https://github.com/litecoin-project/litecoin.git). Doing this in windows with VmWare OSX 10.9.1(64bit).
I cloned it and in terminal ran:
make -f makefile.osx USE_UPNP=-
It spits out this error:
Undefined symbols for architecture x86_64:
"boost::program_options::to_internal(std::string const&)", referenced from:
boost::program_options::detail::basic_config_file_iterator<char>::getline(std::string&) in util.o
"boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool)", referenced from:
boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::istream&, std::set<std::string, std::less<std::string>, std::allocator<std::string> > const&, bool) in util.o
"Db::verify(char const*, char const*, std::ostream*, unsigned int)", referenced from:
CDBEnv::Verify(std::string, bool (*)(CDBEnv&, std::string)) in db.o
CDBEnv::Salvage(std::string, bool, std::vector<std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<unsigned char, std::allocator<unsigned char> > >, std::allocator<std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<unsigned char, std::allocator<unsigned char> > > > >&) in db.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [litecoind] Error 1
I've been googling like crazy but can't seem to find a proper solution.

Boost.Python - undefined symbols error even though the lib files are linked

I'm testing Boost.Python and have run into some issues.
I managed to complete the "Hello World" example without a glitch (http://www.boost.org/doc/libs/1_54_0/libs/python/doc/tutorial/doc/html/index.html) - everything compiled and I was able to use the .so properly in Python.
However, as soon as I introduced classes into my test file (http://www.boost.org/doc/libs/1_54_0/libs/python/doc/tutorial/doc/html/python/exposing.html), the compiler started screaming
Undefined symbols for architecture x86_64:
"boost::python::objects::function_object(boost::python::objects::py_function const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)", referenced from:
boost::python::api::object boost::python::detail::make_function_aux<void (World::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), boost::python::default_call_policies, boost::mpl::vector3<void, World&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, mpl_::int_<0> >(void (World::*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >), boost::python::default_call_policies const&, boost::mpl::vector3<void, World&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>) in SHLibPy.o
boost::python::api::object boost::python::detail::make_function_aux<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > (World::*)(), boost::python::default_call_policies, boost::mpl::vector2<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, World&>, mpl_::int_<0> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > (World::*)(), boost::python::default_call_policies const&, boost::mpl::vector2<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, World&> const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>) in SHLibPy.o
boost::python::api::object boost::python::detail::make_function_aux<void (*)(_object*), boost::python::default_call_policies, boost::mpl::vector2<void, _object*>, mpl_::int_<0> >(void (*)(_object*), boost::python::default_call_policies const&, boost::mpl::vector2<void, _object*> const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>) in SHLibPy.o
"boost::python::objects::register_dynamic_id_aux(boost::python::type_info, std::__1::pair<void*, boost::python::type_info> (*)(void*))", referenced from:
void boost::python::objects::register_dynamic_id<World>(World*) in SHLibPy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It seems to suggest that the lib files are not linked, but I've included them in XCode
Am I missing something? Thanks very much!
I found out why. Turns out that I'm using the standard library with C++11 support. To fix the issue, I rebuilt boost using brew as follows
brew -v install --with-icu --build-from-source --with-c++11 boost

Boost library linking error in Xcode

Boost was installed and make by: brew install boost
Added the header path /usr/local/Cellar/boost/1.53.0/include to User Header Search Path
Added the library path /usr/local/Cellar/boost/1.53.0/lib to Library Search Path
main.cpp
#include <fstream>
#include <sstream>
#include <string>
#include "test.cpp"
void test(){
Test instance(true, 'm', 50, 17.89, "fuzhijie");
stringstream binary_sstream;
boost::archive::binary_oarchive binary_oa(binary_sstream);
binary_oa << instance;
}
int main(int argc, const char * argv[])
{
test();
return 0;
}
When I press CTRL+b, the following error message is shown:
Undefined symbols for architecture x86_64:
"boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init()", referenced from:
boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init(unsigned int) in main.o
"boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void boost::archive::save_access::save_primitive<boost::archive::binary_oarchive, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(boost::archive::binary_oarchive&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
"boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::basic_binary_oprimitive(std::__1::basic_streambuf<char, std::__1::char_traits<char> >&, bool)", referenced from:
boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
"boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~basic_binary_oprimitive()", referenced from:
boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~binary_oarchive_impl() in main.o
boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone have any suggestions on how to fix this?
The reason is maybe you have compiler gcc5 or gcc6.
And your code has used different compile flag with your boost library.
Detail please read this link
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If still can not link, add change project's makefile compiler option to 0.
-D_GLIBCXX_USE_CXX11_ABI=0
======Update=======
The real solution should be install the new boost libraries (v1.62) for gcc6 or gcc5.

Resources