mjbots/rpi_bazel

RPI Bazel having issue while trying to compile boost

cjds opened this issue · 2 comments

cjds commented

When trying to compile the following code,

#include <iostream>
#include <boost/iostreams/device/mapped_file.hpp>
class MmapStateMachine
{
public:
    explicit MmapStateMachine(boost::iostreams::mapped_file_source& file)
    {
      
    }

    ~MmapStateMachine()
    {
      file_.close();
    }
  private:
    boost::iostreams::mapped_file_source file_;
    std::string error_;
};

I'm getting a linker error

DEBUG: Rule 'com_github_nelhage_rules_boost' indicated that a canonical reproducible form can be obtained>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by main.cc
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(__clang_call_terminate)

ld.lld: error: undefined symbol: std::__1::ios_base::__set_badbit_and_consider_rethrow()
>>> referenced by ostream:744 (external/org_llvm_libcxx/include/ostream:744)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<>>> referenced by ostream:745 (external/org_llvm_libcxx/include/ostream:745)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by ostream:745 (external/org_llvm_libcxx/include/ostream:745)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))

>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
 >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by main.cc
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(__clang_call_terminate)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))

ld.lld: error: undefined symbol: __cxa_begin_catch
>>> referenced by ostream:741 (external/org_llvm_libcxx/include/ostream:741)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by main.cc
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(__clang_call_terminate)

ld.lld: error: undefined symbol: std::__1::ios_base::__set_badbit_and_consider_rethrow()
>>> referenced by ostream:744 (external/org_llvm_libcxx/include/ostream:744)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))

ld.lld: error: undefined symbol: __cxa_end_catch
>>> referenced by ostream:745 (external/org_llvm_libcxx/include/ostream:745)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))
>>> referenced by ostream:745 (external/org_llvm_libcxx/include/ostream:745)
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int))

ld.lld: error: undefined symbol: std::terminate()
>>> referenced by main.cc
>>>               bazel-out/armeabihf-dbg/bin/holster/_objs/platform/main.pic.o:(__clang_call_terminate)

This is what the reference to boost looks like in the WORKSPACE

workspace(name = 'rpicar')

BAZEL_VERSION = "3.0.0"
BAZEL_VERSION_SHA = "3efb903ef885339a271445a9940642df704f97297fbe268f131d4fe36b02ea80"

load("//build-tools/workspace:default.bzl", "add_default_repositories")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

add_default_repositories()

load("@rpi_bazel//tools/workspace:default.bzl",
     rpi_bazel_add = "add_default_repositories")
rpi_bazel_add()


load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "com_github_nelhage_rules_boost",
    commit = "ccc90b00c2fae7267cc25b77199fb992acd5e799",
    remote = "https://github.com/nelhage/rules_boost",
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

In the current version of rpi_bazel, you have to manually list the C++ standard library as a dependency in cc_binary rules. Something like:

cc_binary(
  name = "my_thing",
  srcs = ["foo.cc"],
  deps = ["@org_llvm_libcxx//:libcxx"],
)

Can you give that a try?

cjds commented

That works great. Thanks :-)