2

I am still struggling with libc++ and boost.

i compiled the boost with libc++ like here: How to compile/link Boost with clang++/libc++?

now i am seeing this compile error on one of my machine while the other one compiles perfectly fine with the exact code. Both of them has the same compiler version and environment variables are the same too.

Here is the error:

Linking CXX executable main
/opt/local/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/clang++    -arch x86_64 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ CMakeFiles/main.dir/main.cpp.o  -o main  /usr/lib/libpython2.7.dylib /opt/local/lib/libboost_program_options-mt-d.a /opt/local/lib/libboost_filesystem-mt-d.a /opt/local/lib/libboost_system-mt.a /opt/local/lib/libboost_date_time-mt.a /opt/local/lib/libboost_python-mt.a /opt/local/lib/libboost_log-mt.a /opt/local/lib/libboost_thread-mt.a 
Undefined symbols for architecture x86_64:
  "__ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6appendIPwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueERS5_E4typeES9_S9_", referenced from:
      std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > boost::detail::convert<wchar_t, char, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, char const*, char const*, char const*&, wchar_t*, wchar_t*, wchar_t*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > >) in libboost_program_options-mt-d.a(convert.o)
  "__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendIPcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueERS5_E4typeES9_S9_", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > boost::detail::convert<char, wchar_t, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > > >(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, boost::_bi::bind_t<std::__1::codecvt_base::result, boost::_mfi::cmf7<std::__1::codecvt_base::result, std::__1::codecvt<wchar_t, char, __mbstate_t>, __mbstate_t&, wchar_t const*, wchar_t const*, wchar_t const*&, char*, char*, char*&>, boost::_bi::list8<boost::_bi::value<std::__1::codecvt<wchar_t, char, __mbstate_t> const*>, boost::arg<1>, boost::arg<2>, boost::arg<3>, boost::arg<4>, boost::arg<5>, boost::arg<6>, boost::arg<7> > >) in libboost_program_options-mt-d.a(convert.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[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

I am still stuck with ABI incompatibility issue?

Here is the code:

#include <iostream>
#include <string>
#include <tuple>
#include <mutex>
#include <boost/filesystem.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/error_code.hpp>
#include <boost/program_options.hpp>
#include <CoreFoundation/CoreFoundation.h>
namespace po = boost::program_options;
int main(int ac, char* av[])
{
    using namespace std;
    std::mutex mymutex;
    std::tuple<int, int ,char> mytuple;

    boost::filesystem::path mypath("/usr/local/bin");
    boost::filesystem::path agaain("/usr");

    try {

        po::options_description desc("Allowed options");
        desc.add_options()
            ("help", "produce help message")
            ("compression", po::value<double>(), "set compression level")
        ;

        po::variables_map vm;        
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);    

        if (vm.count("help")) {
            cout << desc << "\n";
            return 0;
        }

        if (vm.count("compression")) {
            cout << "Compression level was set to " 
                 << vm["compression"].as<double>() << ".\n";
        } else {
            cout << "Compression level was not set.\n";
        }
    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "\n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!\n";
    }

    return 0;
}

the code compiles fine, but only errors out when linking. Here is the extra info from compile:

chen@work:build$ make VERBOSE=1
/opt/local/bin/cmake -H/Users/chen/Code/clang -B/Users/chen/Code/clang/build --check-build-system CMakeFiles/Makefile.cmake 0
/opt/local/bin/cmake -E cmake_progress_start /Users/chen/Code/clang/build/CMakeFiles /Users/chen/Code/clang/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
cd /Users/chen/Code/clang/build && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /Users/chen/Code/clang /Users/chen/Code/clang /Users/chen/Code/clang/build /Users/chen/Code/clang/build /Users/chen/Code/clang/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/Users/chen/Code/clang/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/Users/chen/Code/clang/build/CMakeFiles/main.dir/depend.internal".
Dependee "/Users/chen/Code/clang/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/chen/Code/clang/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
/opt/local/bin/cmake -E cmake_progress_report /Users/chen/Code/clang/build/CMakeFiles 1
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/usr/bin/clang++    -arch x86_64 -I/Users/chen/Code/clang -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Headers -I/Users/chen/Code/clang/Utilities/includes    -std=c++11 -stdlib=libc++ -o CMakeFiles/main.dir/main.cpp.o -c /Users/chen/Code/clang/main.cpp

On the other hand, on the machine that compiles fine, i can literally "SEE" the speed of libc++. When used in Xcode, it's very very fast and code completion with libc++ is amazing.

But before i enjoy further, I really want to get to the bottom of this...

Community
  • 1
  • 1
Negative Zero
  • 1,224
  • 3
  • 10
  • 19
  • 1
    Quick test: does adding `-std=c++11` to the command line help? The reference to `enable_if` in the missing symbol makes me wonder... – mavam Apr 28 '12 at 01:16
  • you mean add that flag to the linker, right? Just tried, same results. – Negative Zero Apr 28 '12 at 02:26
  • I think on the failed machine, somehow the libiconv is probably messed up. My boost library isn't built properly on that machine. And I notice the difference is iconv (separate) is No on the failed machine. Not sure why though – Negative Zero Apr 28 '12 at 06:10
  • I am going to remove all the macport stuff and rebuild boost, i'll update once I am done. – Negative Zero Apr 28 '12 at 06:22

1 Answers1

1

I just figured out my problem. it was due to Boost not compiled properly because libiconv is not recognized by bjam in my other machine. I guess the reason that it was not recognized is probably because i installed macport. Immediately after i uninstall all the macport stuff, bjam can recognize libiconv and build boost properly under libc++ except signals, but that's alright.

Negative Zero
  • 1,224
  • 3
  • 10
  • 19