How to compile C++ programs with libbcc


Mauricio Vasquez
 

Dear All,

I have been using libbcc with a C++ application without problems for a while. However, when I tried this with bcc master I got some linker errors.

Even with a basic example I get the same errors:

test_overflow.cpp:

#include <bcc/BPF.h>
#include <iostream>

const std::string BPF_PROGRAM1 = R"(
BPF_TABLE("array", int, uint64_t, myarray, 1);
)";

int main(void) {
  ebpf::BPF bpf1;
  ebpf::StatusTuple res(0);

  res = bpf1.init(BPF_PROGRAM1);
  if (res.code() != 0) {
    std::cout << "error on init " << std::endl;
    return -1;
  }

}

g++ test_overflow.cpp -lbcc --std=c++11

test_overflow.cpp:(.text+0x8b): undefined reference to `ebpf::BPF::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, 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&, std::vector<ebpf::USDT, std::allocator<ebpf::USDT> > const&)'
test_overflow.cpp:(.text+0x120): undefined reference to `ebpf::BPF::~BPF()'
test_overflow.cpp:(.text+0x185): undefined reference to `ebpf::BPF::~BPF()'

The last commit to work is https://github.com/iovisor/bcc/commit/dcb77e6 (Remove unused shared_table.h), has something changed on the compilation system?

Thanks,

Mauricio

Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.